diff --git a/server/models/User.js b/server/models/User.js index 83ed3d2..788e720 100644 --- a/server/models/User.js +++ b/server/models/User.js @@ -3,7 +3,10 @@ const {Schema} = mongoose; const userSchema = new Schema({ username: String, - password: String + email: String, + password: String, + registered: String, + lastLogin: Date }); mongoose.model('User', userSchema); \ No newline at end of file diff --git a/server/services/passport.js b/server/services/passport.js index 6252409..e5b6fb2 100644 --- a/server/services/passport.js +++ b/server/services/passport.js @@ -24,7 +24,8 @@ passport.use('local', new LocalStrategy( User.findOne({username: username}) .then(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.hash(newUser.password, salt, (err, hash) => { if (err) throw err; @@ -44,6 +45,8 @@ passport.use('local', new LocalStrategy( if (err) throw err; if (isMatch) { + const lastLogin = Date.now() + User.updateOne(user._id, lastLogin) return done(null, user); } else { return done(null, false, {message: 'Wrong password'});