LT-274: Fix blank date in last login dialog on first logon
- Remove redundant lastLoginModal.js file - Refactor userAccountMenu.js
This commit is contained in:
parent
3b993dadc0
commit
28a904b290
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
@ -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
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
@ -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');
|
||||
|
||||
@ -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;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user