From b8a23ab309822ebf2b7f96a39d94e2e29caa34d1 Mon Sep 17 00:00:00 2001 From: Haris Razis Date: Wed, 6 Jan 2021 19:05:08 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A8=20Change=20User=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/models/User.js | 5 ++++- server/services/passport.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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'});