- Refactor ActiveEntry.sigIn method

- Add own Reset password template
- Check password history and validation in Reset Password
- Add expireTimeInMinute in passwordOptions to control expire time of reset link
- Show sending notification while reset link is sent
This commit is contained in:
Aysel Afsar committed 2016-04-14 15:02:22 -04:00
1 parent 7fa4c33064
commit 1e1c4033a6
8 files changed
+367 -238

No files matched your search

@@ -90,40 +90,11 @@ Template.changePassword.events({
ActiveEntry.errorMessages.set('changePasswordError', null);
if (ActiveEntry.successMessages.get('password') && ActiveEntry.successMessages.get('confirm') && oldPassword) {
Meteor.call("checkPasswordExistence", new String(password).hashCode(), function(error, result) {
if (error) {
console.warn(error.message);
ActiveEntry.errorMessages.set('changePasswordError', error.message);
} else {
if (result) {
ActiveEntry.errorMessages.set('changePasswordError', 'Password is used before. Please change your new password.');
} else {
ActiveEntry.errorMessages.set('changePasswordError', null);
// If password is not found in password history, change the password
Accounts.changePassword(oldPassword, confirmPassword, function(error) {
if (error) {
console.warn(error);
ActiveEntry.errorMessages.set('changePasswordError', error.message);
} else {
// Save the new password
ActiveEntry.insertHashedPassword(confirmPassword);
// Update password expiration date
ActiveEntry.updatePasswordSetDate();
// Logout
ActiveEntry.signOut();
// Go to signIn page for new entry
Router.go('/entrySignIn');
}
});
}
}
});
if (ActiveEntry.errorMessages.get('password') || ActiveEntry.errorMessages.get('confirm') || !oldPassword) {
return;
}
ActiveEntry.changePassword(oldPassword, password);
}
});
@@ -28,45 +28,3 @@
</div>
</div>
</template>
<template name="resetPassword">
{{#if resetPassword}}
<div id="resetPassword" class="page entryPage" style="{{getOpacityWithCorner}}">
<div class="content-scrollable">
<div class="wrapper-auth">
<div class="entryLogo" style="background-image: url('{{getLogoUrl}}')"></div>
<h1 id="signInPageTitle" class="title-auth">Reset Password</h1>
<div id="signInPageMessage" class="subtitle-auth" >Improve your clinical practice with checklists.</div>
<form>
{{#if resetPasswordErrorMessages}}
<div id="errorMessages" class="list-errors">
{{#each resetPasswordErrorMessages}}
<div class="alert alert-danger list-item">{{this}}</div>
{{/each}}
</div>
{{/if}}
<div class="input-symbol ">
<input id="resetPasswordInput" type="password" name="password" placeholder="Password" style="{{getPasswordStyling}}" />
<span class="fa fa-lock" title="Password"></span>
<!-- <span class="icon-lock" title="Password"></span> -->
</div>
<br>
<br>
<div class="input-symbol">
<input id="resetPasswordConfirmInput" type="password" name="confirm" placeholder="Confirm Password" style="{{getConfirmPasswordStyling}}" />
<span class="fa fa-lock" title="Confirm Password"></span>
<!-- <span class="icon-lock" title="Confirm Password"></span> -->
</div>
<br>
<br>
</form>
<button id="resetPasswordButton" type="submit" class="btn-gray btn-main btn-large" style="{{getButtonColor}}">Reset Password</button><br><br>
</div>
</div>
</div>
{{/if}}
</template>
@@ -5,16 +5,6 @@ Router.route('/forgotPassword', {
template: "forgotPassword"
});
Router.route('/resetPassword/:token', {
template: 'resetPassword',
name: 'resetPassword',
onBeforeAction: function() {
var token = this.params.token;
Session.set('_resetPasswordToken', token);
this.next();
}
});
Template.forgotPassword.helpers({
getForgotPasswordMessageColor: function (){
if (ActiveEntry.errorMessages.get('forgotPassword')) {
@@ -37,48 +27,10 @@ Template.forgotPassword.helpers({
Template.forgotPassword.events({
"submit": function (event, template) {
event.preventDefault();
console.log('send reminder!');
ActiveEntry.successMessages.set("forgotPassword", "Your password reset email is sending...");
var emailAddress = $('#signInPageEmailInput').val();
ActiveEntry.forgotPassword(emailAddress);
}
});
// Reset password template
Template.resetPassword.helpers({
resetPassword: function(){
return Session.get('_resetPasswordToken');
},
resetPasswordErrorMessages: function() {
if (ActiveEntry.errorMessages.get("password")) {
return [ActiveEntry.errorMessages.get("password")];
}
if (ActiveEntry.errorMessages.get("confirm")) {
return [ActiveEntry.errorMessages.get("confirm")];
}
return;
}
});
Template.resetPassword.events({
'keyup #resetPasswordInput': function (event, template) {
var password = $('#resetPasswordInput').val();
ActiveEntry.verifyPassword(password);
ActiveEntry.errorMessages.set('forgotPassword', null);
},
'keyup #resetPasswordConfirmInput': function (event, template) {
var password = $('#resetPasswordInput').val();
var confirmPassword = $('#resetPasswordConfirmInput').val();
ActiveEntry.verifyConfirmPassword(password, confirmPassword);
ActiveEntry.errorMessages.set('forgotPassword', null);
},
'click #resetPasswordButton': function(e, template) {
e.preventDefault();
var password = $('#resetPasswordInput').val();
var passwordConfirm = $('#resetPasswordConfirmInput').val();
ActiveEntry.resetPassword(password, passwordConfirm);
}
});
@@ -0,0 +1,42 @@
<template name="resetPassword">
{{#if resetPassword}}
<div id="resetPassword" class="page entryPage" style="{{getOpacityWithCorner}}">
<div class="content-scrollable">
<div class="wrapper-auth">
<div class="entryLogo" style="background-image: url('{{getLogoUrl}}')"></div>
<h1 id="signInPageTitle" class="title-auth">Reset Password</h1>
<p id="signInPageMessage" class="subtitle-auth" style="{{getResetPasswordInMessageColor}}">{{{getResetPasswordMessage}}}</p>
<form>
{{#if resetPasswordErrorMessages}}
<div id="errorMessages" class="list-errors">
{{#each resetPasswordErrorMessages}}
<div class="alert alert-danger list-item">{{this}}</div>
{{/each}}
</div>
{{/if}}
<div class="input-symbol ">
<input id="resetPasswordInput" type="password" name="password" placeholder="Password" style="{{getPasswordStyling}}" />
<span class="fa fa-lock" title="Password"></span>
<!-- <span class="icon-lock" title="Password"></span> -->
</div>
<br>
<br>
<div class="input-symbol">
<input id="resetPasswordConfirmInput" type="password" name="confirm" placeholder="Confirm Password" style="{{getConfirmPasswordStyling}}" />
<span class="fa fa-lock" title="Confirm Password"></span>
<!-- <span class="icon-lock" title="Confirm Password"></span> -->
</div>
<br>
<br>
</form>
<button id="resetPasswordButton" type="submit" class="btn-gray btn-main btn-large" style="{{getButtonColor}}">Reset Password</button><br><br>
</div>
</div>
</div>
{{/if}}
</template>
@@ -0,0 +1,67 @@
Router.route('/resetPassword/:token', {
template: 'resetPassword',
name: 'resetPassword',
onBeforeAction: function() {
var token = this.params.token;
Session.set('_resetPasswordToken', token);
this.next();
}
});
// Reset password template
Template.resetPassword.helpers({
getResetPasswordInMessageColor: function (){
if (ActiveEntry.errorMessages.get('resetPasswordError')) {
return "color: #a94442; background-color: #f2dede; border-color: #ebccd1;"
} else {
return "color: black;"
}
},
getResetPasswordMessage: function (){
if (ActiveEntry.errorMessages.get('resetPasswordError')) {
return ActiveEntry.errorMessages.get('resetPasswordError');
} else {
return Session.get('defaultSignInMessage');
}
},
resetPassword: function(){
return Session.get('_resetPasswordToken');
},
resetPasswordErrorMessages: function() {
if (ActiveEntry.errorMessages.get("password")) {
return [ActiveEntry.errorMessages.get("password")];
}
if (ActiveEntry.errorMessages.get("confirm")) {
return [ActiveEntry.errorMessages.get("confirm")];
}
return;
}
});
Template.resetPassword.events({
'keyup #resetPasswordInput': function (event, template) {
var password = $('#resetPasswordInput').val();
ActiveEntry.verifyPassword(password);
ActiveEntry.errorMessages.set('resetPasswordError', null);
},
'keyup #resetPasswordConfirmInput': function (event, template) {
var password = $('#resetPasswordInput').val();
var confirmPassword = $('#resetPasswordConfirmInput').val();
ActiveEntry.verifyConfirmPassword(password, confirmPassword);
ActiveEntry.errorMessages.set('resetPasswordError', null);
},
'click #resetPasswordButton': function(e, template) {
e.preventDefault();
var password = $('#resetPasswordInput').val();
var passwordConfirm = $('#resetPasswordConfirmInput').val();
if (ActiveEntry.errorMessages.get('password') || ActiveEntry.errorMessages.get('confirm')) {
return;
}
ActiveEntry.resetPassword(password, passwordConfirm);
}
});