From 28a904b29045e51ffaca7cca0b8d8a73a79e4415 Mon Sep 17 00:00:00 2001 From: Aysel Afsar Date: Wed, 24 Aug 2016 11:03:21 -0400 Subject: [PATCH] LT-274: Fix blank date in last login dialog on first logon - Remove redundant lastLoginModal.js file - Refactor userAccountMenu.js --- LesionTracker/.meteor/packages | 1 + LesionTracker/.meteor/versions | 2 + .../lastLoginModal/lastLoginModal.js | 9 -- .../userAccountMenu/userAccountMenu.js | 116 +++++++++++------- Packages/lesiontracker/package.js | 1 - Packages/lesiontracker/server/reviewers.js | 8 +- 6 files changed, 81 insertions(+), 56 deletions(-) delete mode 100644 Packages/lesiontracker/client/components/lastLoginModal/lastLoginModal.js diff --git a/LesionTracker/.meteor/packages b/LesionTracker/.meteor/packages index 9dceea041..063656cd3 100644 --- a/LesionTracker/.meteor/packages +++ b/LesionTracker/.meteor/packages @@ -64,3 +64,4 @@ fastclick@1.0.12 standard-minifier-css@1.1.8 standard-minifier-js@1.1.8 johdirr:meteor-git-rev +u2622:persistent-session diff --git a/LesionTracker/.meteor/versions b/LesionTracker/.meteor/versions index 7d4b6c902..91c298cc5 100644 --- a/LesionTracker/.meteor/versions +++ b/LesionTracker/.meteor/versions @@ -3,6 +3,7 @@ accounts-password@1.2.12 aldeed:simple-schema@1.5.3 aldeed:template-extension@4.0.0 allow-deny@1.0.5 +amplify@1.0.0 anti:gagarin@0.4.11 anti:i18n@0.4.3 arsnebula:reactive-promise@0.9.1 @@ -124,6 +125,7 @@ tracker@1.1.0 twbs:bootstrap@3.3.6 typ:accounts-ldap@1.0.1 typ:ldapjs@0.7.3 +u2622:persistent-session@0.4.4 ui@1.0.11 underscore@1.0.9 url@1.0.10 diff --git a/Packages/lesiontracker/client/components/lastLoginModal/lastLoginModal.js b/Packages/lesiontracker/client/components/lastLoginModal/lastLoginModal.js deleted file mode 100644 index 388677bf0..000000000 --- a/Packages/lesiontracker/client/components/lastLoginModal/lastLoginModal.js +++ /dev/null @@ -1,9 +0,0 @@ -Template.lastLoginModal.helpers({ - lastLoginDate: function() { - var userLoginDate = ReactiveMethod.call('getPriorLoginDate'); - if (userLoginDate && userLoginDate.priorLoginDate) { - return moment(userLoginDate.priorLoginDate).format("MMMM Do YYYY, HH:mm:ss A"); - } - return; - } -}); \ No newline at end of file diff --git a/Packages/lesiontracker/client/components/userAccountMenu/userAccountMenu.js b/Packages/lesiontracker/client/components/userAccountMenu/userAccountMenu.js index 58ec7edaf..6d75389fb 100644 --- a/Packages/lesiontracker/client/components/userAccountMenu/userAccountMenu.js +++ b/Packages/lesiontracker/client/components/userAccountMenu/userAccountMenu.js @@ -1,3 +1,10 @@ +import { Template } from 'meteor/templating'; +import { ReactiveVar } from 'meteor/reactive-var'; +import { Session } from 'meteor/session'; + +// Display the last login modal as default +Session.setDefault('displayLastLoginModal', true); + Template.userAccountMenu.helpers({ name: function() { var nameSplit = Meteor.user().profile.fullName.split(' '); @@ -29,68 +36,87 @@ Template.userAccountMenu.events({ $('#serverInformationModal').modal('show'); }, 'click #logoutButton': function() { - // Remove reviewers info for the user - Meteor.call('removeUserFromReviewers', Meteor.userId()); - Meteor.logout(function() { Router.go('/entrySignIn'); }); } }); -Template.userAccountMenu.onRendered(function() { - var oldUserId; - var lastLoginModalInterval; +Template.userAccountMenu.onCreated(function userAccountMenuCreated() { + const instance = Template.instance(); - this.autorun(function() { - // Hook login/logout - var user = Meteor.user(); - if (!user) { + // Create reactive last login date + instance.lastLoginDate = new ReactiveVar(); + + // We need oldUser to remove Reviewers if the user logged out + let oldUser; + + // Get last login date + Meteor.call('getPriorLoginDate', function(error, lastLoginDate){ + if (error) { + console.log(error); return; } - var newUserId = user._id; + // Format the last login date + const formattedLastLoginDate = moment(lastLoginDate).format("MMMM Do YYYY, HH:mm:ss A"); - if (oldUserId === null && newUserId) { - Session.set('showLastLoginModal', true); + instance.lastLoginDate.set(formattedLastLoginDate); - // Log - HipaaLogger.logEvent({ - eventType: 'init', - userId: user._id, - userName: user.fullName - }); + }); - } else if (newUserId === null && oldUserId) { - // Set showLastLoginModal as null - Session.set('showLastLoginModal', null); - - // Destroy interval for last login modal - Meteor.clearInterval(lastLoginModalInterval); - console.log('The user logged out'); - - // Log - // TODO: eventType is not defined for logout in hipaa-audit-log - /*HipaaLogger.logEvent({ - eventType: 'logout', - userId: oldUserId, - userName: userName - });*/ - - // Remove the user from Reviewers - Meteor.call('removeUserFromReviewers', oldUserId); + instance.autorun(function() { + const lastLoginDate = instance.lastLoginDate.get(); + if (!lastLoginDate) { + return; } - oldUserId = Meteor.userId(); + // Hook login/logout + var user = Meteor.user(); + if (!user) { + // Display last login modal for the next login + Session.setPersistent('displayLastLoginModal', true); + + if (oldUser) { + // Log Signout + // TODO: eventType for logout is not defined + // HipaaLogger.logEvent({ + // eventType: 'logout', + // userId: oldUser._id, + // userName: oldUser.profile.fullName + // }); + + // Remove the user by oldUserId from Reviewers + Meteor.call('removeUserFromReviewers', oldUser._id); + } + return; + } + + // Set oldUser + oldUser = user; // Trigger last login date popup - if (Session.get('showLastLoginModal')) { - Modal.show('lastLoginModal'); - - lastLoginModalInterval = Meteor.setInterval(function() { - Modal.hide('lastLoginModal'); - Session.set('showLastLoginModal', null); - }, 3000); + if (!Session.get('displayLastLoginModal')) { + return; } + + // Displaye the modal + Modal.show('lastLoginModal', { + lastLoginDate: lastLoginDate + }); + + // Hide the modal after 5sec + Meteor.setTimeout(() => { + Modal.hide('lastLoginModal'); + Session.setPersistent('displayLastLoginModal', false); + }, 5000); + + // Log signin + HipaaLogger.logEvent({ + eventType: 'init', + userId: user._id, + userName: user.profile.fullName + }); + }); }); \ No newline at end of file diff --git a/Packages/lesiontracker/package.js b/Packages/lesiontracker/package.js index ad16e3a8a..9f06f4a55 100644 --- a/Packages/lesiontracker/package.js +++ b/Packages/lesiontracker/package.js @@ -197,7 +197,6 @@ Package.onUse(function(api) { api.addFiles('client/components/confirmRemoveTimepointAssociation/confirmRemoveTimepointAssociation.js', 'client'); api.addFiles('client/components/lastLoginModal/lastLoginModal.html', 'client'); - api.addFiles('client/components/lastLoginModal/lastLoginModal.js', 'client'); api.addFiles('client/components/confirmDeleteDialog/confirmDeleteDialog.html', 'client'); api.addFiles('client/components/confirmDeleteDialog/confirmDeleteDialog.styl', 'client'); diff --git a/Packages/lesiontracker/server/reviewers.js b/Packages/lesiontracker/server/reviewers.js index 27aa79d84..fb228c166 100644 --- a/Packages/lesiontracker/server/reviewers.js +++ b/Packages/lesiontracker/server/reviewers.js @@ -85,7 +85,13 @@ Meteor.methods({ }, getPriorLoginDate: function() { - return Meteor.users.findOne({_id: Meteor.userId()}, {fields: {priorLoginDate: 1}}); + return Meteor.users.findOne({ + _id: Meteor.userId() + }, { + fields: { + priorLoginDate: 1 + } + }).priorLoginDate; } });