Redesign 1 bcrypt #226
6 changed files with 59 additions and 22 deletions
|
@ -16,7 +16,6 @@ module.exports = {
|
|||
return db.Channel.findOne({where: {channelName: publishParams.channel_name}});
|
||||
})
|
||||
.then(user => {
|
||||
logger.debug('user:', user);
|
||||
let certificateId;
|
||||
if (user) {
|
||||
certificateId = user.channelClaimId;
|
||||
|
|
|
@ -26,16 +26,20 @@ module.exports = new PassportLocalStrategy(
|
|||
logger.debug('user found:', user.dataValues);
|
||||
userInfo['id'] = user.id;
|
||||
userInfo['userName'] = user.userName;
|
||||
return user.getChannel();
|
||||
})
|
||||
.then(channel => {
|
||||
userInfo['channelName'] = channel.channelName;
|
||||
userInfo['channelClaimId'] = channel.channelClaimId;
|
||||
return db.getShortChannelIdFromLongChannelId(channel.channelClaimId, channel.channelName);
|
||||
})
|
||||
.then(shortChannelId => {
|
||||
userInfo['shortChannelId'] = shortChannelId;
|
||||
return done(null, userInfo);
|
||||
// channel stuff
|
||||
return user.getChannel()
|
||||
.then(channel => {
|
||||
userInfo['channelName'] = channel.channelName;
|
||||
userInfo['channelClaimId'] = channel.channelClaimId;
|
||||
return db.getShortChannelIdFromLongChannelId(channel.channelClaimId, channel.channelName);
|
||||
})
|
||||
.then(shortChannelId => {
|
||||
userInfo['shortChannelId'] = shortChannelId;
|
||||
return done(null, userInfo);
|
||||
})
|
||||
.catch(error => {
|
||||
throw error;
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
return done(error);
|
||||
|
|
|
@ -47,7 +47,6 @@ function publishNewChannel (event) {
|
|||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
if (error.name === 'ChannelNameError' || error.name === 'ChannelPasswordError'){
|
||||
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
|
||||
showError(channelNameErrorDisplayElement, error.message);
|
||||
|
|
|
@ -31,7 +31,7 @@ function postRequest (url, params) {
|
|||
if ( xhttp.status == 200) {
|
||||
resolve(xhttp.response);
|
||||
} else if (xhttp.status == 401) {
|
||||
reject('wrong username or password');
|
||||
reject( new AuthenticationError('wrong username or password'));
|
||||
} else {
|
||||
reject('request failed with status:' + xhttp.status);
|
||||
};
|
||||
|
@ -168,4 +168,12 @@ function ChannelPasswordError(message) {
|
|||
this.stack = (new Error()).stack;
|
||||
}
|
||||
ChannelPasswordError.prototype = Object.create(Error.prototype);
|
||||
ChannelPasswordError.prototype.constructor = ChannelPasswordError;
|
||||
ChannelPasswordError.prototype.constructor = ChannelPasswordError;
|
||||
|
||||
function AuthenticationError(message) {
|
||||
this.name = 'AuthenticationError';
|
||||
this.message = message || 'Default Message';
|
||||
this.stack = (new Error()).stack;
|
||||
}
|
||||
AuthenticationError.prototype = Object.create(Error.prototype);
|
||||
AuthenticationError.prototype.constructor = AuthenticationError;
|
|
@ -47,14 +47,18 @@ function loginToChannel (event) {
|
|||
const password = document.getElementById('channel-login-password-input').value;
|
||||
// prevent default
|
||||
event.preventDefault()
|
||||
// send request
|
||||
sendAuthRequest(userName, password, '/login')
|
||||
// update session cookie with new channel name and id's
|
||||
validateNewChannelLogin(userName, password)
|
||||
.then(() => {
|
||||
console.log('channel login in progress');
|
||||
// send request
|
||||
return sendAuthRequest(userName, password, '/login')
|
||||
})
|
||||
.then(result => {
|
||||
// update session cookie with new channel name and id's
|
||||
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // replace the current cookies
|
||||
})
|
||||
// update channel selection
|
||||
.then(() => {
|
||||
// update channel selection
|
||||
if (window.location.pathname === '/') {
|
||||
// remove old channel and replace with new one & select it
|
||||
replaceChannelOptionInPublishChannelSelect();
|
||||
|
@ -67,7 +71,11 @@ function loginToChannel (event) {
|
|||
})
|
||||
.catch(error => {
|
||||
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
||||
showError(loginErrorDisplayElement, error);
|
||||
console.log('login failure:', error);
|
||||
if (error.name){
|
||||
showError(loginErrorDisplayElement, error.message);
|
||||
} else {
|
||||
console.log('login failure:', error);
|
||||
showError(loginErrorDisplayElement, 'There was an error logging into your channel');
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ function validateClaimName (name) {
|
|||
// validate the characters in the 'name' field
|
||||
const invalidCharacters = /[^A-Za-z0-9,-]/g.exec(name);
|
||||
if (invalidCharacters) {
|
||||
throw new NameError('"' + invalidCharacters + '" characters are not allowed in the url.');
|
||||
throw new NameError('"' + invalidCharacters + '" characters are not allowed');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +58,7 @@ function validateChannelName (name) {
|
|||
// validate the characters in the 'name' field
|
||||
const invalidCharacters = /[^A-Za-z0-9,-,@]/g.exec(name);
|
||||
if (invalidCharacters) {
|
||||
throw new ChannelNameError('"' + invalidCharacters + '" characters are not allowed in the channel name.');
|
||||
throw new ChannelNameError('"' + invalidCharacters + '" characters are not allowed');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,4 +218,23 @@ function validateNewChannelSubmission(userName, password){
|
|||
reject(error);
|
||||
});
|
||||
});
|
||||
}
|
||||
// validation function which checks all aspects of a new channel login
|
||||
function validateNewChannelLogin(userName, password){
|
||||
const channelName = `@${userName}`;
|
||||
return new Promise(function (resolve, reject) {
|
||||
// 1. validate name
|
||||
try {
|
||||
validateChannelName(channelName);
|
||||
} catch (error) {
|
||||
return reject(error);
|
||||
}
|
||||
// 2. validate password
|
||||
try {
|
||||
validatePassword(password);
|
||||
} catch (error) {
|
||||
return reject(error);
|
||||
}
|
||||
resolve();
|
||||
});
|
||||
}
|
Loading…
Add table
Reference in a new issue