LT-106: User accounts shall be made inactive after 6 months of inactivity

This commit is contained in:
Aysel Afsar 2016-02-15 16:40:53 -05:00
parent d19e402847
commit d83b2f4199
3 changed files with 120 additions and 74 deletions

View File

@ -14,7 +14,7 @@
<button id="logoutButton" class="btn-primary btn-main btn-large" style="{{getButtonColor}}">Logout</button> <button id="logoutButton" class="btn-primary btn-main btn-large" style="{{getButtonColor}}">Logout</button>
{{else}} {{else}}
<h1 id="signInPageTitle" class="title-auth">Sign In.</h1> <h1 id="signInPageTitle" class="title-auth">Sign In.</h1>
<p id="signInPageMessage" class="subtitle-auth" style="{{getSignInMessageColor}}">{{getSignInMessage}}</p> <p id="signInPageMessage" class="subtitle-auth" style="{{getSignInMessageColor}}">{{{getSignInMessage}}}</p>
<form> <form>
<div class="input-symbol"> <div class="input-symbol">

View File

@ -29,7 +29,8 @@ if (Meteor.isClient) {
//requireStrongPasswords: false //requireStrongPasswords: false
passwordHistoryCount: 6, passwordHistoryCount: 6,
failedAttemptsLimit: 5, failedAttemptsLimit: 5,
passwordExpirationDays: 90 passwordExpirationDays: 90,
inactivityPeriodDays: 180
} }
}); });
@ -60,7 +61,8 @@ ActiveEntry.configure = function (configObject) {
//requireStrongPasswords: false //requireStrongPasswords: false
passwordHistoryCount: 6, passwordHistoryCount: 6,
failedAttemptsLimit: 5, failedAttemptsLimit: 5,
passwordExpirationDays: 90 passwordExpirationDays: 90,
inactivityPeriodDays: 180
} }
} }
Session.set('Photonic.ActiveEntry', configObject); Session.set('Photonic.ActiveEntry', configObject);
@ -130,12 +132,24 @@ ActiveEntry.signIn = function (emailValue, passwordValue){
var ActiveEntryConfig = Session.get('Photonic.ActiveEntry'); var ActiveEntryConfig = Session.get('Photonic.ActiveEntry');
var failedAttemptsLimit = ActiveEntryConfig && ActiveEntryConfig.passwordOptions && ActiveEntryConfig.passwordOptions.failedAttemptsLimit || 5; var failedAttemptsLimit = ActiveEntryConfig && ActiveEntryConfig.passwordOptions && ActiveEntryConfig.passwordOptions.failedAttemptsLimit || 5;
var passwordExpirationDays = ActiveEntryConfig && ActiveEntryConfig.passwordOptions && ActiveEntryConfig.passwordOptions.passwordExpirationDays || 90; var passwordExpirationDays = ActiveEntryConfig && ActiveEntryConfig.passwordOptions && ActiveEntryConfig.passwordOptions.passwordExpirationDays || 90;
var inactivityPeriodDays = ActiveEntryConfig && ActiveEntryConfig.passwordOptions && ActiveEntryConfig.passwordOptions.inactivityPeriodDays || 180;
Meteor.call("isAccountInactive",[emailValue,inactivityPeriodDays], function(error, isAccountInactive) {
if (error) {
console.warn(error);
} else {
if (isAccountInactive) {
// Lock account
Meteor.call("lockAccount", emailValue);
ActiveEntry.errorMessages.set('signInError', "Your account has been locked due to inactivity.");
return;
} else {
// Check account is locked // Check account is locked
Meteor.call("isAccountLocked", function (error, isAccountLocked) { Meteor.call("isAccountLocked", function (error, isAccountLocked) {
if (error) { if (error) {
console.warn(error); console.warn(error);
} else { } else {
if (isAccountLocked) { if (isAccountLocked) {
ActiveEntry.errorMessages.set('signInError', "Your account has been locked."); ActiveEntry.errorMessages.set('signInError', "Your account has been locked.");
return; return;
@ -146,8 +160,8 @@ ActiveEntry.signIn = function (emailValue, passwordValue){
console.warn(error.message); console.warn(error.message);
} else { } else {
if (failedAttemptsCount != failedAttemptsLimit) { if (failedAttemptsCount != failedAttemptsLimit) {
Meteor.loginWithPassword({email: emailValue}, passwordValue, function (error, result) { Meteor.loginWithPassword({email: emailValue}, passwordValue, function (loginError, result) {
if (error) { if (loginError) {
// Login failed // Login failed
Meteor.call("updateFailedAttempts", [emailValue, failedAttemptsLimit], function(error, failedAttemptCount) { Meteor.call("updateFailedAttempts", [emailValue, failedAttemptsLimit], function(error, failedAttemptCount) {
if (error) { if (error) {
@ -156,14 +170,14 @@ ActiveEntry.signIn = function (emailValue, passwordValue){
if (failedAttemptCount == failedAttemptsLimit) { if (failedAttemptCount == failedAttemptsLimit) {
ActiveEntry.errorMessages.set('signInError', "Too many failed login attempts. Your account has been locked."); ActiveEntry.errorMessages.set('signInError', "Too many failed login attempts. Your account has been locked.");
} else if (failedAttemptCount < failedAttemptsLimit) {
ActiveEntry.errorMessages.set('signInError', loginError.message + "<br />" +(failedAttemptsLimit - failedAttemptCount) + " attempts remaining.");
} else { } else {
ActiveEntry.errorMessages.set('signInError', (failedAttemptsLimit - failedAttemptCount) + " attempts remaining."); ActiveEntry.errorMessages.set('signInError', loginError.message);
} }
} }
}); });
} else { } else {
console.log('result', result);
// Reset failed attempts // Reset failed attempts
Meteor.call("resetFailedAttempts", emailValue); Meteor.call("resetFailedAttempts", emailValue);
@ -173,6 +187,9 @@ ActiveEntry.signIn = function (emailValue, passwordValue){
if (error) { if (error) {
console.warn(error); console.warn(error);
} else { } else {
// Update last login time
Meteor.call("updateLastLoginDate");
if (isPasswordExpired) { if (isPasswordExpired) {
ActiveEntry.errorMessages.set('changePasswordError', 'Your password expired. Please change your password.'); ActiveEntry.errorMessages.set('changePasswordError', 'Your password expired. Please change your password.');
Router.go('/changePassword'); Router.go('/changePassword');
@ -194,7 +211,9 @@ ActiveEntry.signIn = function (emailValue, passwordValue){
} }
}); });
}
}
});
}; };
@ -227,32 +246,21 @@ ActiveEntry.signUp = function (emailValue, passwordValue, confirmPassword, fullN
} }
}, function (error, result) { }, function (error, result) {
if (error) { if (error) {
console.log(error);
ActiveEntry.errorMessages.set('signInError', error.message); ActiveEntry.errorMessages.set('signInError', error.message);
} else { } else {
// Add password in previous password field // Add password in previousPasswords field
ActiveEntry.insertHashedPassword(passwordValue); ActiveEntry.insertHashedPassword(passwordValue);
// Update password set date // Update password set date
ActiveEntry.updatePasswordSetDate(); ActiveEntry.updatePasswordSetDate();
// Update last login time
Meteor.call("updateLastLoginDate");
var ActiveEntryConfig = Session.get('Photonic.ActiveEntry'); var ActiveEntryConfig = Session.get('Photonic.ActiveEntry');
Router.go(ActiveEntryConfig.signUp.destination); Router.go(ActiveEntryConfig.signUp.destination);
} }
}); });
// Meteor.loginWithPassword({email: emailValue}, passwordValue, function (error, result) {
// if (error) {
// console.log(error);
// Session.set('errorMessage', error);
// }
//
// if (result) {
// console.log('result', result);
// }
// var ActiveEntryConfig = Session.get('Photonic.ActiveEntry');
// console.log('ActiveEntryConfig', JSON.stringify(ActiveEntryConfig));
// Router.go(ActiveEntryConfig.signIn.destination);
// });
}; };
// Insert hashed password in previousPasswords fields // Insert hashed password in previousPasswords fields

View File

@ -79,6 +79,16 @@ Meteor.methods({
return failedAttemptCount + 1; return failedAttemptCount + 1;
}, },
lockAccount: function(emailAddress) {
// Check if the user actually exists, and if not, stop here
var currentUser = Meteor.users.findOne({"emails.address": emailAddress});
if (!currentUser) {
return;
}
Meteor.users.update({"emails.address": emailAddress}, {$set: {"profile.isLocked": true}});
},
resetFailedAttempts: function(emailAddress) { resetFailedAttempts: function(emailAddress) {
Meteor.users.update({"emails.address": emailAddress}, {$set: {failedPasswordAttempts: 0}}); Meteor.users.update({"emails.address": emailAddress}, {$set: {failedPasswordAttempts: 0}});
}, },
@ -106,6 +116,34 @@ Meteor.methods({
} }
return currentUser.profile.isLocked || false; return currentUser.profile.isLocked || false;
},
updateLastLoginDate: function () {
Meteor.users.update({_id: Meteor.userId()}, {$set: {lastLoginDate: new Date()}});
},
isAccountInactive: function (inactivityParameters) {
var emailAddress = inactivityParameters[0];
var inactivityPeriodDays = inactivityParameters[1];
// Check if the user actually exists, and if not, stop here
var currentUser = Meteor.users.findOne({"emails.address": emailAddress});
console.log(currentUser);
if (!currentUser) {
return;
}
console.log(currentUser);
var lastLoginDate = currentUser.lastLoginDate;
console.log(lastLoginDate);
lastLoginDate.setDate(lastLoginDate.getDate() + inactivityPeriodDays);
console.log(lastLoginDate);
if (lastLoginDate <= new Date()) {
return true;
}
return false;
} }
}); });