Upload refactor #242
2 changed files with 11 additions and 10 deletions
|
@ -2,14 +2,8 @@ const db = require('../models');
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
authenticateChannelCredentials (skipAuth, channelName, userPassword) {
|
authenticateChannelCredentials (channelName, userPassword) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// skip authentication if not needed
|
|
||||||
if (skipAuth) {
|
|
||||||
resolve(skipAuth);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// authentication
|
|
||||||
const userName = channelName.substring(1);
|
const userName = channelName.substring(1);
|
||||||
logger.debug(`authenticateChannelCredentials > channelName: ${channelName} username: ${userName} pass: ${userPassword}`);
|
logger.debug(`authenticateChannelCredentials > channelName: ${channelName} username: ${userName} pass: ${userPassword}`);
|
||||||
db.User
|
db.User
|
||||||
|
|
|
@ -9,6 +9,13 @@ const errorHandlers = require('../helpers/errorHandlers.js');
|
||||||
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
|
||||||
const { authenticateChannelCredentials } = require('../auth/authentication.js');
|
const { authenticateChannelCredentials } = require('../auth/authentication.js');
|
||||||
|
|
||||||
|
function authenticateOrSkip (skipAuth, channelName, channelPassword) {
|
||||||
|
if (skipAuth) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return authenticateChannelCredentials(channelName, channelPassword);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to run a claim_list request on the daemon
|
// route to run a claim_list request on the daemon
|
||||||
app.get('/api/claim_list/:name', ({ headers, ip, originalUrl, params }, res) => {
|
app.get('/api/claim_list/:name', ({ headers, ip, originalUrl, params }, res) => {
|
||||||
|
@ -126,9 +133,9 @@ module.exports = (app) => {
|
||||||
channelName = cleanseChannelName(channelName);
|
channelName = cleanseChannelName(channelName);
|
||||||
logger.debug(`name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
|
logger.debug(`name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
|
||||||
// check channel authorization
|
// check channel authorization
|
||||||
authenticateChannelCredentials(skipAuth, channelName, channelPassword)
|
authenticateOrSkip(skipAuth)
|
||||||
.then(result => {
|
.then(authenticated => {
|
||||||
if (!result) {
|
if (!authenticated) {
|
||||||
throw new Error('Authentication failed, you do not have access to that channel');
|
throw new Error('Authentication failed, you do not have access to that channel');
|
||||||
}
|
}
|
||||||
// make sure the claim name is available
|
// make sure the claim name is available
|
||||||
|
|
Loading…
Add table
Reference in a new issue