turned authOrSkip into promise

This commit is contained in:
bill bittner 2017-11-13 14:20:37 -05:00
parent f7a6f52b75
commit 07660576b1
4 changed files with 13 additions and 15 deletions

View file

@ -34,4 +34,12 @@ module.exports = {
});
});
},
authenticateOrSkip (skipAuth, channelName, channelPassword) {
return new Promise((resolve, reject) => {
if (skipAuth) {
return resolve(true);
}
return resolve(module.exports.authenticateChannelCredentials(channelName, channelPassword));
});
},
};

View file

@ -25,7 +25,6 @@ module.exports = (sequelize, { STRING }) => {
};
User.prototype.comparePassword = function (password, callback) {
logger.debug(`User.prototype.comparePassword ${password} ${this.password}`);
bcrypt.compare(password, this.password, callback);
};

View file

@ -8,7 +8,7 @@ function getRequest (url) {
if ( xhttp.status == 200) {
resolve(xhttp.response);
} else if (xhttp.status == 401) {
reject('Wrong username or password');
reject('Wrong channel name or password');
} else {
reject('request failed with status:' + xhttp.status);
};
@ -29,7 +29,7 @@ function postRequest (url, params) {
if ( xhttp.status == 200) {
resolve(xhttp.response);
} else if (xhttp.status == 401) {
reject( new AuthenticationError('Wrong username or password'));
reject( new AuthenticationError('Wrong channel name or password'));
} else {
reject('request failed with status:' + xhttp.status);
};

View file

@ -7,14 +7,7 @@ const { getClaimList, resolveUri } = require('../helpers/lbryApi.js');
const { createPublishParams, validateApiPublishRequest, validatePublishSubmission, cleanseChannelName, checkClaimNameAvailability, checkChannelAvailability } = require('../helpers/publishHelpers.js');
const errorHandlers = require('../helpers/errorHandlers.js');
const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
const { authenticateChannelCredentials } = require('../auth/authentication.js');
function authenticateOrSkip (skipAuth, channelName, channelPassword) {
if (skipAuth) {
return true;
}
return authenticateChannelCredentials(channelName, channelPassword);
}
const { authenticateOrSkip } = require('../auth/authentication.js');
module.exports = (app) => {
// route to run a claim_list request on the daemon
@ -79,8 +72,6 @@ module.exports = (app) => {
});
// route to run a publish request on the daemon
app.post('/api/publish', multipartMiddleware, ({ body, files, ip, originalUrl, user }, res) => {
logger.debug('api/publish body:', body);
logger.debug('api/publish body:', files);
let file, fileName, filePath, fileType, name, nsfw, license, title, description, thumbnail, anonymous, skipAuth, channelName, channelPassword;
// validate that mandatory parts of the request are present
try {
@ -131,9 +122,9 @@ module.exports = (app) => {
}
}
channelName = cleanseChannelName(channelName);
logger.debug(`name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
logger.debug(`/api/publish > name: ${name}, license: ${license} title: "${title}" description: "${description}" channelName: "${channelName}" channelPassword: "${channelPassword}" nsfw: "${nsfw}"`);
// check channel authorization
authenticateOrSkip(skipAuth)
authenticateOrSkip(skipAuth, channelName, channelPassword)
.then(authenticated => {
if (!authenticated) {
throw new Error('Authentication failed, you do not have access to that channel');