Local authentication

This commit is contained in:
NGPixel 2016-10-30 23:03:36 -04:00
parent dc6fc449f0
commit 3d20fee5df
8 changed files with 90 additions and 42 deletions

View File

@ -19,11 +19,12 @@
- [Installation Guide](https://requarks-wiki.readme.io/docs/prerequisites) - [Installation Guide](https://requarks-wiki.readme.io/docs/prerequisites)
##### Milestones ##### Milestones
- [ ] Account Management
- [ ] Assets Management - [ ] Assets Management
- [x] Images - [x] Images
- [ ] Files/Documents - [ ] Files/Documents
- [ ] Authentication - [x] Authentication
- [ ] Local - [x] Local
- [x] Microsoft Account - [x] Microsoft Account
- [x] Google ID - [x] Google ID
- [x] Facebook - [x] Facebook

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,8 @@
@import './layout/_base'; @import './layout/_base';
@import './layout/_mixins'; @import './layout/_mixins';
@import './libs/animate.min.css';
body { body {
padding: 0; padding: 0;
margin: 0; margin: 0;
@ -80,6 +82,34 @@ a {
animation: headerIntro 3s ease; animation: headerIntro 3s ease;
} }
h3 {
font-size: 1.25rem;
font-weight: normal;
color: #FB8C00;
padding: 0;
margin: 0;
animation: shake 1s ease;
> .fa {
margin-right: 7px;
}
}
h4 {
font-size: 0.8rem;
font-weight: normal;
color: rgba(255,255,255,0.7);
padding: 0;
margin: 0 0 15px 0;
animation: fadeIn 3s ease;
}
form {
display: flex;
flex-direction: column;
}
input[type=text], input[type=password] { input[type=text], input[type=password] {
width: 350px; width: 350px;
max-width: 80vw; max-width: 80vw;
@ -96,7 +126,7 @@ a {
&:focus { &:focus {
outline: none; outline: none;
border-color: rgba(255,255,255,0.8); border-color: #FB8C00;
} }
} }
@ -148,6 +178,10 @@ a {
background-color: #009688; background-color: #009688;
border-color: lighten(#009688, 10%); border-color: lighten(#009688, 10%);
&:focus {
border-color: #FFF;
}
&:hover { &:hover {
background-color: darken(#009688, 10%); background-color: darken(#009688, 10%);
} }
@ -158,6 +192,10 @@ a {
background-color: #2196F3; background-color: #2196F3;
border-color: lighten(#2196F3, 10%); border-color: lighten(#2196F3, 10%);
&:focus {
border-color: #FFF;
}
&:hover { &:hover {
background-color: darken(#2196F3, 10%); background-color: darken(#2196F3, 10%);
} }
@ -168,6 +206,10 @@ a {
background-color: #673AB7; background-color: #673AB7;
border-color: lighten(#673AB7, 10%); border-color: lighten(#673AB7, 10%);
&:focus {
border-color: #FFF;
}
&:hover { &:hover {
background-color: darken(#673AB7, 10%); background-color: darken(#673AB7, 10%);
} }

View File

@ -35,28 +35,26 @@ router.get('/login', function(req, res, next) {
}); });
router.post('/login', bruteforce.prevent, function(req, res, next) { router.post('/login', bruteforce.prevent, function(req, res, next) {
passport.authenticate('local', function(err, user, info) { passport.authenticate('local', function(err, user, info) {
if (err) { return next(err); } if (err) { return next(err); }
if (!user) { if (!user) {
req.flash('alert', { req.flash('alert', {
class: 'error', title: 'Invalid login',
title: 'Invalid login', message: "The email or password is invalid."
message: "The email or password is invalid.", });
iconClass: 'fa-times' return res.redirect('/login');
}); }
return res.redirect('/login');
}
req.logIn(user, function(err) { req.logIn(user, function(err) {
if (err) { return next(err); } if (err) { return next(err); }
req.brute.reset(function () { req.brute.reset(function () {
return res.redirect('/'); return res.redirect('/');
}); });
}); });
})(req, res, next); })(req, res, next);
}); });
/** /**

View File

@ -2,7 +2,9 @@
module.exports = (socket) => { module.exports = (socket) => {
console.log(socket.request.user); if(!socket.request.user.logged_in) {
return;
}
//----------------------------------------- //-----------------------------------------
// SEARCH // SEARCH

View File

@ -34,23 +34,24 @@ module.exports = function(passport, appconfig) {
passport.use('local', passport.use('local',
new LocalStrategy({ new LocalStrategy({
usernameField : 'email', usernameField : 'email',
passwordField : 'password', passwordField : 'password'
passReqToCallback : true
}, },
function(req, uEmail, uPassword, done) { (uEmail, uPassword, done) => {
db.User.findOne({ 'email' : uEmail }).then((user) => { db.User.findOne({ email: uEmail, provider: 'local' }).then((user) => {
if (user) { if(user) {
user.validatePassword(uPassword).then((isValid) => { return user.validatePassword(uPassword).then(() => {
return (isValid) ? done(null, user) : done(null, false); return done(null, user) || true;
}).catch((err) => {
return done(err, null);
}); });
} else { } else {
return done(null, false); return done(new Error('Invalid Login'), null);
} }
}).catch((err) => { }).catch((err) => {
done(err); done(err, null) ;
}); });
}) }
); ));
} }

View File

@ -78,9 +78,8 @@ userSchema.statics.hashPassword = (rawPwd) => {
}; };
userSchema.methods.validatePassword = function(rawPwd) { userSchema.methods.validatePassword = function(rawPwd) {
let self = this; return bcrypt.compare(rawPwd, this.password).then((isValid) => {
return bcrypt.hash(rawPwd).then((pwd) => { return (isValid) ? true : Promise.reject(new Error('Invalid Login'));
return (self.password === pwd) ? true : Promise.reject(new Error('Invalid Password'));
}); });
}; };

View File

@ -32,10 +32,16 @@ html
#root #root
h1= appconfig.title h1= appconfig.title
h2 Login required h2 Login required
if appflash.length > 0
h3
i.fa.fa-warning
= appflash[0].title
h4= appflash[0].message
if appconfig.auth.local.enabled if appconfig.auth.local.enabled
input#login-user(type='text', placeholder='Email address') form(method='post', action='/login')
input#login-pass(type='password', placeholder='Password') input#login-user(type='text', name='email', placeholder='Email address')
button Log In input#login-pass(type='password', name='password', placeholder='Password')
button(type='submit') Log In
if appconfig.authStrategies.socialEnabled if appconfig.authStrategies.socialEnabled
#social #social
if appconfig.auth.local.enabled if appconfig.auth.local.enabled
@ -58,5 +64,4 @@ html
= t('footer.poweredby') + ' ' = t('footer.poweredby') + ' '
a.icon(href='https://github.com/Requarks/wiki') a.icon(href='https://github.com/Requarks/wiki')
i.fa.fa-github i.fa.fa-github
a(href='https://github.com/Requarks/wiki') Requarks Wiki a(href='https://github.com/Requarks/wiki') Requarks Wiki