login completed
This commit is contained in:
parent
3acd89f93d
commit
ef475ba951
4 changed files with 22 additions and 12 deletions
|
@ -10,18 +10,19 @@ module.exports = new PassportLocalStrategy(
|
|||
passReqToCallback: true,
|
||||
},
|
||||
(req, username, password, done) => {
|
||||
logger.debug('verifying loggin attempt');
|
||||
username = `@${username}`;
|
||||
logger.debug(`verifying loggin attempt ${username} ${password}`);
|
||||
return db.User
|
||||
.findOne({where: {channelName: username}})
|
||||
.then(user => {
|
||||
if (!user) {
|
||||
logger.debug('no user found');
|
||||
return done(null, false, {message: 'Incorrect username or password.'});
|
||||
}
|
||||
if (!user.validPassword(password, user.password)) {
|
||||
logger.debug('incorrect password');
|
||||
return done(null, false, {message: 'Incorrect username or password.'});
|
||||
}
|
||||
logger.debug('user', user.dataValues);
|
||||
logger.debug('user found:', user.dataValues);
|
||||
return done(null, user);
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
@ -14,10 +14,12 @@ function sendAuthRequest (channelName, password, url) { // url === /signup or /
|
|||
if (this.response == true) {
|
||||
resolve();
|
||||
} else {
|
||||
reject( new NameError("Your request could not be completed"));
|
||||
reject(new NameError('Your request succedded but could not be completed'));
|
||||
}
|
||||
} else if (this.status == 401) {
|
||||
reject('Incorrect username or password')
|
||||
} else {
|
||||
reject("createChannel request failed with status:" + this.status);
|
||||
reject('Auth request failed with status:' + this.status);
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
<h2>Log In</h2>
|
||||
<p>Log in to an existing channel:</p>
|
||||
<form id="login-form">
|
||||
<div id="login-error-display-element" class="info-message info-message--failure"></div>
|
||||
<div>
|
||||
<label>Username:</label>
|
||||
@ <input type="text" id="login-channel-name" class="input-text input-text--primary"/>
|
||||
|
@ -50,12 +51,13 @@
|
|||
// validate submission
|
||||
validateNewChannelSubmission(channelName, password)
|
||||
.then(() => {
|
||||
document.getElementById('publish-channel-form').innerHTML = '<p>Creating your new channel...</p>';
|
||||
return sendAuthRequest(channelName, password, '/signup'); // post the request
|
||||
})
|
||||
.then(() => {
|
||||
console.log('signup success');
|
||||
document.getElementById('publish-channel-form').innerHTML = '<p>Your channel has been successfully created! Redirecting you now...</p>';
|
||||
window.location.href = `/${channelName}`;
|
||||
document.getElementById('publish-channel-form').innerHTML = '<p>Your channel has been successfully created! Signing you in now...</p>';
|
||||
window.location.href = '/';
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.name === 'ChannelNameError'){
|
||||
|
@ -70,15 +72,17 @@
|
|||
function loginToChannel (event) {
|
||||
const channelName = `@${document.getElementById('login-channel-name').value}`;
|
||||
const password = document.getElementById('login-channel-password').value;
|
||||
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
||||
// prevent default action
|
||||
event.preventDefault()
|
||||
// send request
|
||||
sendAuthRequest(channelName, password, '/login')
|
||||
.then(() => {
|
||||
.then( () => {
|
||||
console.log('login success');
|
||||
//window.location.href = `/${channelName}`;
|
||||
window.location.href = `/${channelName}`;
|
||||
})
|
||||
.catch(error => {
|
||||
showError(loginErrorDisplayElement, error);
|
||||
console.log('login failure:', error);
|
||||
})
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
<div id="channel-login-details" hidden="true">
|
||||
<p>
|
||||
<form id="channel-login-form">
|
||||
<div id="login-error-display-element" class="info-message info-message--failure"></div>
|
||||
<div>
|
||||
<label for="login-channel-name">Channel Name: </label>
|
||||
@<input type="text" name="login-channel-name" id="login-channel-name" class="input-text input-text--primary" placeholder="" value="">
|
||||
|
@ -79,14 +80,14 @@
|
|||
// validate submission
|
||||
validateNewChannelSubmission(channelName, password)
|
||||
.then(() => {
|
||||
document.getElementById('channel-create-details').innerHTML = '<p>Your channel is being created...</p>';
|
||||
document.getElementById('channel-create-details').innerHTML = '<p>Creating your new channel...</p>';
|
||||
return sendAuthRequest(channelName, password, '/signup') // post the request
|
||||
})
|
||||
.then(() => {
|
||||
console.log('success');
|
||||
document.getElementById('channel-create-details').innerHTML = '<p>Your channel has been successfully created!</p>';
|
||||
// referesh window logged in as the channel
|
||||
window.location.href = `/`;
|
||||
window.location.href = '/';
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.name === 'ChannelNameError'){
|
||||
|
@ -102,15 +103,17 @@
|
|||
function loginToChannel (event) {
|
||||
const channelName = `@${document.getElementById('login-channel-name').value}`;
|
||||
const password = document.getElementById('login-channel-password').value;
|
||||
const loginErrorDisplayElement = document.getElementById('login-error-display-element');
|
||||
// prevent default
|
||||
event.preventDefault()
|
||||
// send request
|
||||
sendAuthRequest(channelName, password, '/login')
|
||||
.then(() => {
|
||||
console.log('login success');
|
||||
//window.location.href = `/${channelName}`;
|
||||
window.location.href = '/';
|
||||
})
|
||||
.catch(error => {
|
||||
showError(loginErrorDisplayElement, error);
|
||||
console.log('login failure:', error);
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue