Browse Source

🔨 Change User model

main
Haris Razis 4 years ago
parent
commit
b8a23ab309
  1. 5
      server/models/User.js
  2. 5
      server/services/passport.js

5
server/models/User.js

@ -3,7 +3,10 @@ const {Schema} = mongoose;
const userSchema = new Schema({ const userSchema = new Schema({
username: String, username: String,
password: String email: String,
password: String,
registered: String,
lastLogin: Date
}); });
mongoose.model('User', userSchema); mongoose.model('User', userSchema);

5
server/services/passport.js

@ -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'});

Loading…
Cancel
Save