Merge pull request #1085 from jc21/improved-new-password-error-messages

Improved new password error messages
This commit is contained in:
jc21 2021-05-13 08:24:12 +10:00 committed by GitHub
commit 5269c957ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -4,6 +4,7 @@
<button type="button" class="close cancel" aria-label="Close" data-dismiss="modal">&nbsp;</button>
</div>
<div class="modal-body">
<div class="alert alert-danger" id="error-info" role="alert"></div>
<form>
<% if (isSelf()) { %>
<div class="form-group">
@ -15,7 +16,7 @@
<div class="form-group">
<label class="form-label"><%- i18n('users', 'new-password') %></label>
<input type="password" name="new_password1" class="form-control" placeholder="" minlength="8" required>
<div class="invalid-feedback secret-error"></div>
<div class="invalid-feedback new-secret-error"></div>
</div>
<div class="form-group">
<label class="form-label"><%- i18n('users', 'confirm-password') %></label>

View File

@ -9,21 +9,23 @@ module.exports = Mn.View.extend({
className: 'modal-dialog',
ui: {
form: 'form',
buttons: '.modal-footer button',
cancel: 'button.cancel',
save: 'button.save',
error: '.secret-error'
form: 'form',
buttons: '.modal-footer button',
cancel: 'button.cancel',
save: 'button.save',
newSecretError: '.new-secret-error',
generalError: '#error-info',
},
events: {
'click @ui.save': function (e) {
e.preventDefault();
this.ui.error.hide();
this.ui.newSecretError.hide();
this.ui.generalError.hide();
let form = this.ui.form.serializeJSON();
if (form.new_password1 !== form.new_password2) {
this.ui.error.text('Passwords do not match!').show();
this.ui.newSecretError.text('Passwords do not match!').show();
return;
}
@ -40,7 +42,11 @@ module.exports = Mn.View.extend({
App.Controller.showUsers();
})
.catch(err => {
this.ui.error.text(err.message).show();
// Change error message to make it a little clearer
if (err.message === 'Invalid password') {
err.message = 'Current password is invalid';
}
this.ui.generalError.text(err.message).show();
this.ui.buttons.prop('disabled', false).removeClass('btn-disabled');
});
}
@ -54,5 +60,10 @@ module.exports = Mn.View.extend({
return {
isSelf: this.isSelf.bind(this)
};
}
},
onRender: function () {
this.ui.newSecretError.hide();
this.ui.generalError.hide();
},
});