|
@ -24,7 +24,8 @@ passport.use('local', new LocalStrategy( |
|
|
User.findOne({username: username}) |
|
|
User.findOne({username: username}) |
|
|
.then(user => { |
|
|
.then(user => { |
|
|
if (!user) { |
|
|
if (!user) { |
|
|
const newUser = new User({username, password}); |
|
|
const lastLogin = Date.now() |
|
|
|
|
|
const newUser = new User({username, password, lastLogin}); |
|
|
bcrypt.genSalt(10, (err, salt) => { |
|
|
bcrypt.genSalt(10, (err, salt) => { |
|
|
bcrypt.hash(newUser.password, salt, (err, hash) => { |
|
|
bcrypt.hash(newUser.password, salt, (err, hash) => { |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
@ -44,6 +45,8 @@ passport.use('local', new LocalStrategy( |
|
|
if (err) throw err; |
|
|
if (err) throw err; |
|
|
|
|
|
|
|
|
if (isMatch) { |
|
|
if (isMatch) { |
|
|
|
|
|
const lastLogin = Date.now() |
|
|
|
|
|
User.updateOne(user._id, lastLogin) |
|
|
return done(null, user); |
|
|
return done(null, user); |
|
|
} else { |
|
|
} else { |
|
|
return done(null, false, {message: 'Wrong password'}); |
|
|
return done(null, false, {message: 'Wrong password'}); |
|
|