Authentication #170

Merged
bones7242 merged 43 commits from authentication into master 2017-09-29 02:29:22 +02:00
4 changed files with 13 additions and 11 deletions
Showing only changes of commit 1a502c6ad8 - Show all commits

View file

@ -14,14 +14,14 @@ module.exports = new PassportLocalStrategy(
return db.User return db.User
.findOne({where: {channelName: username}}) .findOne({where: {channelName: username}})
.then(user => { .then(user => {
logger.debug('user', user.dataValues);
if (!user) { if (!user) {
return done(null, false, {message: 'Incorrect username or password.'}); return done(null, false, {message: 'Incorrect username or password.'});
} }
if (!user.validPassword(password, user.password)) { if (!user.validPassword(password, user.password)) {
return done(null, false, {message: 'Incorrect username or password.'}); return done(null, false, {message: 'Incorrect username or password.'});
} }
return done(null, user); // user.dataValues? logger.debug('user', user.dataValues);
return done(null, user);
}) })
.catch(error => { .catch(error => {
return done(error); return done(error);

View file

@ -14,8 +14,8 @@ module.exports = new PassportLocalStrategy(
(req, username, password, done) => { (req, username, password, done) => {
logger.debug('new channel signup request'); logger.debug('new channel signup request');
const address = config.get('WalletConfig.LbryClaimAddress'); const address = config.get('WalletConfig.LbryClaimAddress');
// validate raw inputs (username, password) // server-side validaton of raw inputs (username, password)
username = '@' + username;
// create the channel and retrieve the metadata // create the channel and retrieve the metadata
return lbryApi.createChannel(username) return lbryApi.createChannel(username)
.then(channelTx => { .then(channelTx => {

View file

@ -26,7 +26,7 @@ function sendSignupRequest (channelName, password) {
} }
function publishNewChannel (event) { function publishNewChannel (event) {
const channelName = document.getElementById('new-channel-name').value; const channelName = `@${document.getElementById('new-channel-name').value}`;
const password = document.getElementById('new-channel-password').value; const password = document.getElementById('new-channel-password').value;
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name'); const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
const passwordErrorDisplayElement = document.getElementById('input-error-password'); const passwordErrorDisplayElement = document.getElementById('input-error-password');
@ -40,7 +40,7 @@ function publishNewChannel (event) {
.then(() => { .then(() => {
console.log('success'); console.log('success');
document.getElementById('signup-form').innerHTML = '<p>Your channel has been successfully created! Redirecting you now...</p>'; document.getElementById('signup-form').innerHTML = '<p>Your channel has been successfully created! Redirecting you now...</p>';
window.location.href = '/channelName'; window.location.href = `/${channelName}`;
}) })
.catch(error => { .catch(error => {
if (error.name === 'ChannelNameError'){ if (error.name === 'ChannelNameError'){

View file

@ -56,7 +56,7 @@ function validateChannelName (name) {
function validatePassword (password) { function validatePassword (password) {
if (password.length < 1) { if (password.length < 1) {
throw new ChannelNameError("You must enter a password for you channel"); throw new ChannelPasswordError("You must enter a password for you channel");
} }
} }
@ -172,10 +172,10 @@ function validateFilePublishSubmission(stagedFiles, claimName, channelName){
} }
// if all validation passes, check availability of the name // if all validation passes, check availability of the name
isNameAvailable(claimName, '/api/isClaimAvailable/') isNameAvailable(claimName, '/api/isClaimAvailable/')
.then(function() { .then(() => {
resolve(); resolve();
}) })
.catch(function(error) { .catch(error => {
reject(error); reject(error);
}); });
}); });
@ -198,10 +198,12 @@ function validateNewChannelSubmission(channelName, password){
} }
// 3. if all validation passes, check availability of the name // 3. if all validation passes, check availability of the name
isNameAvailable(channelName, '/api/isChannelAvailable/') // validate the availability isNameAvailable(channelName, '/api/isChannelAvailable/') // validate the availability
.then(function() { .then(() => {
console.log('channel is avaliable');
resolve(); resolve();
}) })
.catch(function(error) { .catch( error => {
console.log('error: channel is not avaliable');
reject(error); reject(error);
}); });
}); });