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}});
|
return db.Channel.findOne({where: {channelName: publishParams.channel_name}});
|
||||||
})
|
})
|
||||||
.then(user => {
|
.then(user => {
|
||||||
logger.debug('user:', user);
|
|
||||||
let certificateId;
|
let certificateId;
|
||||||
if (user) {
|
if (user) {
|
||||||
certificateId = user.channelClaimId;
|
certificateId = user.channelClaimId;
|
||||||
|
|
|
@ -26,16 +26,20 @@ module.exports = new PassportLocalStrategy(
|
||||||
logger.debug('user found:', user.dataValues);
|
logger.debug('user found:', user.dataValues);
|
||||||
userInfo['id'] = user.id;
|
userInfo['id'] = user.id;
|
||||||
userInfo['userName'] = user.userName;
|
userInfo['userName'] = user.userName;
|
||||||
return user.getChannel();
|
// channel stuff
|
||||||
})
|
return user.getChannel()
|
||||||
.then(channel => {
|
.then(channel => {
|
||||||
userInfo['channelName'] = channel.channelName;
|
userInfo['channelName'] = channel.channelName;
|
||||||
userInfo['channelClaimId'] = channel.channelClaimId;
|
userInfo['channelClaimId'] = channel.channelClaimId;
|
||||||
return db.getShortChannelIdFromLongChannelId(channel.channelClaimId, channel.channelName);
|
return db.getShortChannelIdFromLongChannelId(channel.channelClaimId, channel.channelName);
|
||||||
})
|
})
|
||||||
.then(shortChannelId => {
|
.then(shortChannelId => {
|
||||||
userInfo['shortChannelId'] = shortChannelId;
|
userInfo['shortChannelId'] = shortChannelId;
|
||||||
return done(null, userInfo);
|
return done(null, userInfo);
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
return done(error);
|
return done(error);
|
||||||
|
|
|
@ -47,7 +47,6 @@ function publishNewChannel (event) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
|
|
||||||
if (error.name === 'ChannelNameError' || error.name === 'ChannelPasswordError'){
|
if (error.name === 'ChannelNameError' || error.name === 'ChannelPasswordError'){
|
||||||
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
|
const channelNameErrorDisplayElement = document.getElementById('input-error-channel-name');
|
||||||
showError(channelNameErrorDisplayElement, error.message);
|
showError(channelNameErrorDisplayElement, error.message);
|
||||||
|
|
|
@ -31,7 +31,7 @@ function postRequest (url, params) {
|
||||||
if ( xhttp.status == 200) {
|
if ( xhttp.status == 200) {
|
||||||
resolve(xhttp.response);
|
resolve(xhttp.response);
|
||||||
} else if (xhttp.status == 401) {
|
} else if (xhttp.status == 401) {
|
||||||
reject('wrong username or password');
|
reject( new AuthenticationError('wrong username or password'));
|
||||||
} else {
|
} else {
|
||||||
reject('request failed with status:' + xhttp.status);
|
reject('request failed with status:' + xhttp.status);
|
||||||
};
|
};
|
||||||
|
@ -169,3 +169,11 @@ function ChannelPasswordError(message) {
|
||||||
}
|
}
|
||||||
ChannelPasswordError.prototype = Object.create(Error.prototype);
|
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;
|
const password = document.getElementById('channel-login-password-input').value;
|
||||||
// prevent default
|
// prevent default
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
// send request
|
validateNewChannelLogin(userName, password)
|
||||||
sendAuthRequest(userName, password, '/login')
|
.then(() => {
|
||||||
// update session cookie with new channel name and id's
|
console.log('channel login in progress');
|
||||||
|
// send request
|
||||||
|
return sendAuthRequest(userName, password, '/login')
|
||||||
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
|
// update session cookie with new channel name and id's
|
||||||
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // replace the current cookies
|
setUserCookies(result.channelName, result.channelClaimId, result.shortChannelId); // replace the current cookies
|
||||||
})
|
})
|
||||||
// update channel selection
|
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
// update channel selection
|
||||||
if (window.location.pathname === '/') {
|
if (window.location.pathname === '/') {
|
||||||
// remove old channel and replace with new one & select it
|
// remove old channel and replace with new one & select it
|
||||||
replaceChannelOptionInPublishChannelSelect();
|
replaceChannelOptionInPublishChannelSelect();
|
||||||
|
@ -67,7 +71,11 @@ function loginToChannel (event) {
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
||||||
showError(loginErrorDisplayElement, error);
|
if (error.name){
|
||||||
console.log('login failure:', error);
|
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
|
// validate the characters in the 'name' field
|
||||||
const invalidCharacters = /[^A-Za-z0-9,-]/g.exec(name);
|
const invalidCharacters = /[^A-Za-z0-9,-]/g.exec(name);
|
||||||
if (invalidCharacters) {
|
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
|
// validate the characters in the 'name' field
|
||||||
const invalidCharacters = /[^A-Za-z0-9,-,@]/g.exec(name);
|
const invalidCharacters = /[^A-Za-z0-9,-,@]/g.exec(name);
|
||||||
if (invalidCharacters) {
|
if (invalidCharacters) {
|
||||||
throw new ChannelNameError('"' + invalidCharacters + '" characters are not allowed in the channel name.');
|
throw new ChannelNameError('"' + invalidCharacters + '" characters are not allowed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,3 +219,22 @@ function validateNewChannelSubmission(userName, password){
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// 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