From f8d90f1cc6adc7deb4da7d16d953c131eb010816 Mon Sep 17 00:00:00 2001 From: Matt Enlow Date: Thu, 27 Mar 2014 09:28:34 -0600 Subject: [PATCH] Added populate last login time closes #2515 - sets last_login when user is saved if user status changed to active - added integration test in user Basic Operations --- core/server/models/user.js | 2 +- core/test/integration/model/model_users_spec.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/core/server/models/user.js b/core/server/models/user.js index 931447ec07..a77b826193 100644 --- a/core/server/models/user.js +++ b/core/server/models/user.js @@ -177,7 +177,7 @@ User = ghostBookshelf.Model.extend({ }); } - return when(user.set('status', 'active').save()).then(function (user) { + return when(user.set({status : 'active', last_login : new Date()}).save()).then(function (user) { return user; }); }, errors.logAndThrowError); diff --git a/core/test/integration/model/model_users_spec.js b/core/test/integration/model/model_users_spec.js index 8ce5652206..c85bec7101 100644 --- a/core/test/integration/model/model_users_spec.js +++ b/core/test/integration/model/model_users_spec.js @@ -141,6 +141,15 @@ describe('User Model', function run() { }, done); }); + it('sets last login time on successful login', function (done) { + var userData = testUtils.DataGenerator.forModel.users[0]; + + UserModel.check({email: userData.email, pw:userData.password}).then(function (activeUser) { + should.exist(activeUser.get('last_login')); + done(); + }).then(null, done); + }); + it('can\'t add second', function (done) { var userData = testUtils.DataGenerator.forModel.users[1];