also fixes some UX issues and enforces password length check on both
client and server
v1.18.x
psychobunny 10 years ago
parent cc6f37ac4e
commit 799cc9397a

@ -240,25 +240,30 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
var successIcon = '<i class="fa fa-check"></i>'; var successIcon = '<i class="fa fa-check"></i>';
function onPasswordChanged() { function onPasswordChanged() {
passwordvalid = utils.isPasswordValid(password.val());
if (password.val().length < config.minimumPasswordLength) { if (password.val().length < config.minimumPasswordLength) {
showError(password_notify, '[[user:change_password_error_length]]'); showError(password_notify, '[[user:change_password_error_length]]');
} else if (!passwordvalid) { passwordvalid = false;
} else if (!utils.isPasswordValid(password.val())) {
showError(password_notify, '[[user:change_password_error]]'); showError(password_notify, '[[user:change_password_error]]');
passwordvalid = false;
} else { } else {
showSuccess(password_notify, successIcon); showSuccess(password_notify, successIcon);
passwordvalid = true;
} }
} }
function onPasswordConfirmChanged() { function onPasswordConfirmChanged() {
if(password.val()) { if (password.val() !== password_confirm.val()) {
if (password.val() !== password_confirm.val()) { showError(password_confirm_notify, '[[user:change_password_error_match]]');
showError(password_confirm_notify, '[[user:change_password_error_match]]'); passwordsmatch = false;
passwordsmatch = false; } else {
} else { if (password.val()) {
showSuccess(password_confirm_notify, successIcon); showSuccess(password_confirm_notify, successIcon);
passwordsmatch = true; } else {
removeAlert(password_confirm_notify);
} }
passwordsmatch = true;
} }
} }
@ -266,6 +271,9 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
password_confirm.on('blur', onPasswordConfirmChanged); password_confirm.on('blur', onPasswordConfirmChanged);
$('#changePasswordBtn').on('click', function() { $('#changePasswordBtn').on('click', function() {
onPasswordChanged();
onPasswordConfirmChanged();
var btn = $(this); var btn = $(this);
if ((passwordvalid && passwordsmatch) || app.user.isAdmin) { if ((passwordvalid && passwordsmatch) || app.user.isAdmin) {
btn.addClass('disabled').find('i').removeClass('hide'); btn.addClass('disabled').find('i').removeClass('hide');
@ -282,11 +290,21 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
passwordvalid = false; passwordvalid = false;
if (err) { if (err) {
onPasswordChanged();
onPasswordConfirmChanged();
return app.alertError(err.message); return app.alertError(err.message);
} }
app.alertSuccess('[[user:change_password_success]]'); app.alertSuccess('[[user:change_password_success]]');
}); });
} else {
if (!passwordsmatch) {
app.alertError('[[user:change_password_error_match]]');
}
if (!passwordvalid) {
app.alertError('[[user:change_password_error]]');
}
} }
return false; return false;
}); });
@ -349,5 +367,10 @@ define('forum/account/edit', ['forum/account/header', 'uploader', 'translator'],
}); });
} }
function removeAlert(element) {
element.html('');
element.parent().removeClass('alert-success alert-danger');
}
return AccountEdit; return AccountEdit;
}); });

@ -138,7 +138,7 @@ SocketUser.checkStatus = function(socket, uid, callback) {
}; };
SocketUser.changePassword = function(socket, data, callback) { SocketUser.changePassword = function(socket, data, callback) {
if (!data || !data.uid) { if (!data || !data.uid || data.newPassword.length < meta.config.minimumPasswordLength) {
return callback(new Error('[[error:invalid-data]]')); return callback(new Error('[[error:invalid-data]]'));
} }
if (!socket.uid) { if (!socket.uid) {

Loading…
Cancel
Save