mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 11:35:55 +01:00
misc fixes
This commit is contained in:
@@ -119,7 +119,7 @@ $(document).ready(function() {
|
||||
gravatarPicture = data.gravatarpicture;
|
||||
}
|
||||
} else {
|
||||
app.alertError('There was an error updating your profile!');
|
||||
app.alertError('There was an error updating your profile! ' + err.error);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
@@ -222,50 +222,59 @@ $(document).ready(function() {
|
||||
|
||||
function onPasswordChanged() {
|
||||
passwordvalid = utils.isPasswordValid(password.val());
|
||||
if (password.val().length < 6) {
|
||||
if (password.val().length < config.minimumPasswordLength) {
|
||||
password_notify.html('Password too short');
|
||||
password_notify.attr('class', 'label label-danger');
|
||||
password_notify.attr('class', 'alert alert-danger');
|
||||
password_notify.removeClass('hide');
|
||||
} else if(!passwordvalid) {
|
||||
password_notify.html('Invalid password');
|
||||
password_notify.attr('class', 'label label-danger');
|
||||
password_notify.attr('class', 'alert alert-danger');
|
||||
password_notify.removeClass('hide');
|
||||
} else {
|
||||
password_notify.html('OK!');
|
||||
password_notify.attr('class', 'label label-success');
|
||||
password_notify.attr('class', 'alert alert-success');
|
||||
password_notify.removeClass('hide');
|
||||
}
|
||||
|
||||
onPasswordConfirmChanged();
|
||||
}
|
||||
|
||||
function onPasswordConfirmChanged() {
|
||||
if(password_notify.hasClass('alert-danger') || !password_confirm.val()) {
|
||||
password_confirm_notify.addClass('hide');
|
||||
return;
|
||||
}
|
||||
if(password.val() !== password_confirm.val()) {
|
||||
password_confirm_notify.html('Passwords must match!');
|
||||
password_confirm_notify.attr('class', 'label label-danger');
|
||||
password_confirm_notify.attr('class', 'alert alert-danger');
|
||||
password_confirm_notify.removeClass('hide');
|
||||
passwordsmatch = false;
|
||||
} else {
|
||||
password_confirm_notify.html('OK!');
|
||||
password_confirm_notify.attr('class', 'label label-success');
|
||||
password_confirm_notify.attr('class', 'alert alert-success');
|
||||
password_confirm_notify.removeClass('hide');
|
||||
passwordsmatch = true;
|
||||
}
|
||||
}
|
||||
|
||||
password.on('keyup', onPasswordChanged);
|
||||
password_confirm.on('keyup', onPasswordConfirmChanged);
|
||||
password.on('blur', onPasswordChanged);
|
||||
password_confirm.on('blur', onPasswordConfirmChanged);
|
||||
|
||||
$('#changePasswordBtn').on('click', function() {
|
||||
|
||||
if(passwordvalid && passwordsmatch && currentPassword.val()) {
|
||||
socket.emit('api:user.changePassword', {'currentPassword': currentPassword.val(),'newPassword': password.val() }, function(data) {
|
||||
socket.emit('api:user.changePassword', {'currentPassword': currentPassword.val(),'newPassword': password.val() }, function(err) {
|
||||
|
||||
currentPassword.val('');
|
||||
password.val('');
|
||||
password_confirm.val('');
|
||||
password_notify.html('');
|
||||
password_confirm_notify.html('');
|
||||
password_notify.addClass('hide');
|
||||
password_confirm_notify.addClass('hide');
|
||||
passwordsmatch = false;
|
||||
passwordvalid = false;
|
||||
|
||||
if(data.err) {
|
||||
app.alertError(data.err);
|
||||
if(err) {
|
||||
app.alertError(err.error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -149,17 +149,19 @@
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="inputNewPassword">Password</label>
|
||||
<div class="controls">
|
||||
<input class="form-control" type="password" id="inputNewPassword" placeholder="New Password" value=""><span id="password-notify" class="label label-danger"></span>
|
||||
<input class="form-control" type="password" id="inputNewPassword" placeholder="New Password" value="">
|
||||
<div id="password-notify" class="alert alert-danger hide"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="control-group">
|
||||
<label class="control-label" for="inputNewPasswordAgain">Confirm Password</label>
|
||||
<div class="controls">
|
||||
<input class="form-control" type="password" id="inputNewPasswordAgain" placeholder="Confirm Password" value=""><br/><span id="password-confirm-notify" class="label label-danger"></span>
|
||||
<input class="form-control" type="password" id="inputNewPasswordAgain" placeholder="Confirm Password" value="">
|
||||
<div id="password-confirm-notify" class="alert alert-danger hide"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<br/>
|
||||
<div class="form-actions">
|
||||
<a id="changePasswordBtn" href="#" class="btn btn-primary">Change Password</a>
|
||||
</div>
|
||||
|
||||
28
src/user.js
28
src/user.js
@@ -37,7 +37,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
},
|
||||
function(next) {
|
||||
if (email !== undefined) {
|
||||
User.isEmailAvailable(email, function(available) {
|
||||
User.isEmailAvailable(email, function(err, available) {
|
||||
if(err)
|
||||
return next(err);
|
||||
next(!available ? new Error('Email taken!') : null);
|
||||
});
|
||||
} else next();
|
||||
@@ -209,7 +211,9 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
User.getUserField(uid, 'email', function(err, email) {
|
||||
if(email !== data['email']) {
|
||||
User.isEmailAvailable(data['email'], function(available) {
|
||||
User.isEmailAvailable(data['email'], function(err, available) {
|
||||
if(err)
|
||||
return next(err, null);
|
||||
if(!available) {
|
||||
next({error:'Email not available!'}, false);
|
||||
} else {
|
||||
@@ -272,38 +276,30 @@ var utils = require('./../public/src/utils.js'),
|
||||
|
||||
User.isEmailAvailable = function(email, callback) {
|
||||
RDB.exists('email:' + email + ':uid' , function(err, exists) {
|
||||
if(!err) {
|
||||
callback(exists !== 1);
|
||||
return;
|
||||
} else {
|
||||
console.log(err);
|
||||
callback(false);
|
||||
}
|
||||
callback(err, !!exists);
|
||||
});
|
||||
}
|
||||
|
||||
User.changePassword = function(uid, data, callback) {
|
||||
if(!utils.isPasswordValid(data.newPassword)) {
|
||||
callback({err:'Invalid password!'});
|
||||
return;
|
||||
return callback({error:'Invalid password!'});
|
||||
}
|
||||
|
||||
User.getUserField(uid, 'password', function(err, user_password) {
|
||||
bcrypt.compare(data.currentPassword, user_password, function(err, res) {
|
||||
if(err) {
|
||||
console.log(err);
|
||||
callback({err:'bcrpyt compare error!'});
|
||||
return;
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
if (res) {
|
||||
User.hashPassword(data.newPassword, function(err, hash) {
|
||||
User.setUserField(uid, 'password', hash);
|
||||
|
||||
callback({err:null});
|
||||
callback(null);
|
||||
});
|
||||
} else {
|
||||
callback({err:'Your current password is not correct!'});
|
||||
console.log('gg');
|
||||
callback({error:'Your current password is not correct!'});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user