Updated passport local strategy to use usernameEmail usernameField

This commit is contained in:
Sahat Yalkabov
2013-12-04 07:58:17 -05:00
parent 83dbe9c197
commit 12368eaf95
3 changed files with 42 additions and 48 deletions

View File

@ -18,7 +18,7 @@ passport.deserializeUser(function(id, done) {
}); });
passport.use(new LocalStrategy({ passport.use(new LocalStrategy({
usernameField: 'email' usernameField: 'usernameEmail'
}, },
function(email, password, done) { function(email, password, done) {
User.findOne({ email: email }, function(err, user) { User.findOne({ email: email }, function(err, user) {

View File

@ -33,10 +33,7 @@ exports.getLogin = function(req, res) {
*/ */
exports.postLogin = function(req, res, next) { exports.postLogin = function(req, res, next) {
passport.authenticate('local', function(err, user, info) { passport.authenticate('local', function(err, user, info) {
if (err) { if (err) return next(err);
console.log(err);
return next(err);
}
if (!user) { if (!user) {
req.flash('messages', info.message); req.flash('messages', info.message);
return res.redirect('/login'); return res.redirect('/login');

View File

@ -1,46 +1,43 @@
extends layout extends layout
block content block content
.login-wrapper if messages.length
.login-container .alert.alert-danger
h3.text-center strong= messages
span.text-primary PROJECT .login-container
span.text-muted NAME h3.text-center
form(method='POST') span.text-primary PROJECT
.form-group span.text-muted NAME
input.form-control(type='text', name='usernameOrEmail', id='usernameOrEmail', placeholder='Username or Email', autofocus='') form(method='POST')
.form-group .form-group
input.form-control(type='password', name='password', id='password', placeholder='Password') input.form-control(type='text', name='usernameEmail', id='usernameEmail', placeholder='Username or Email', autofocus='')
button(type='submit') .form-group
i.fa.fa-chevron-right input.form-control(type='password', name='password', id='password', placeholder='Password')
.form-options.clearfix button(type='submit')
a.pull-right(href='#') Forgot password? i.fa.fa-chevron-right
.text-left .form-options.clearfix
label.checkbox a.pull-right(href='#') Forgot password?
input(type='checkbox') .text-left
span Remember me label.checkbox
.row input(type='checkbox')
.col-xs-6.col-sm-6.col-md-6 span Remember me
a.btn.btn-primary.btn-block.facebook(href='/auth/facebook') .row
i.fa.fa-facebook .col-xs-6.col-sm-6.col-md-6
| Facebook a.btn.btn-primary.btn-block.facebook(href='/auth/facebook')
.col-xs-6.col-sm-6.col-md-6 i.fa.fa-facebook
a.btn.btn-danger.btn-block.google(href='/auth/google') | Facebook
i.fa.fa-google-plus .col-xs-6.col-sm-6.col-md-6
|   Google a.btn.btn-danger.btn-block.google(href='/auth/google')
.row i.fa.fa-google-plus
.col-xs-6.col-sm-6.col-md-6 |   Google
a.btn.btn-info.btn-block.twitter(href='/auth/twitter') .row
i.fa.fa-twitter .col-xs-6.col-sm-6.col-md-6
|   Twitter a.btn.btn-info.btn-block.twitter(href='/auth/twitter')
.col-xs-6.col-sm-6.col-md-6 i.fa.fa-twitter
a.btn.btn-default.btn-block.github(href='/auth/github') |   Twitter
i.fa.fa-github .col-xs-6.col-sm-6.col-md-6
|   GitHub a.btn.btn-default.btn-block.github(href='/auth/github')
p Don't have an account yet?  i.fa.fa-github
a(href='/signup') Sign up now |   GitHub
p Don't have an account yet? 
a(href='/signup') Sign up now
if messages.length
.alert.alert-danger
strong= messages