misc fixes

v1.18.x
Baris Usakli 12 years ago
parent 325e402d0f
commit 59467c906d

@ -119,7 +119,7 @@ $(document).ready(function() {
gravatarPicture = data.gravatarpicture; gravatarPicture = data.gravatarpicture;
} }
} else { } else {
app.alertError('There was an error updating your profile!'); app.alertError('There was an error updating your profile! ' + err.error);
} }
}); });
return false; return false;
@ -222,50 +222,59 @@ $(document).ready(function() {
function onPasswordChanged() { function onPasswordChanged() {
passwordvalid = utils.isPasswordValid(password.val()); passwordvalid = utils.isPasswordValid(password.val());
if (password.val().length < 6) { if (password.val().length < config.minimumPasswordLength) {
password_notify.html('Password too short'); 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) { } else if(!passwordvalid) {
password_notify.html('Invalid password'); password_notify.html('Invalid password');
password_notify.attr('class', 'label label-danger'); password_notify.attr('class', 'alert alert-danger');
password_notify.removeClass('hide');
} else { } else {
password_notify.html('OK!'); password_notify.html('OK!');
password_notify.attr('class', 'label label-success'); password_notify.attr('class', 'alert alert-success');
password_notify.removeClass('hide');
} }
onPasswordConfirmChanged(); onPasswordConfirmChanged();
} }
function onPasswordConfirmChanged() { function onPasswordConfirmChanged() {
if(password_notify.hasClass('alert-danger') || !password_confirm.val()) {
password_confirm_notify.addClass('hide');
return;
}
if(password.val() !== password_confirm.val()) { if(password.val() !== password_confirm.val()) {
password_confirm_notify.html('Passwords must match!'); 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; passwordsmatch = false;
} else { } else {
password_confirm_notify.html('OK!'); 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; passwordsmatch = true;
} }
} }
password.on('keyup', onPasswordChanged); password.on('blur', onPasswordChanged);
password_confirm.on('keyup', onPasswordConfirmChanged); password_confirm.on('blur', onPasswordConfirmChanged);
$('#changePasswordBtn').on('click', function() { $('#changePasswordBtn').on('click', function() {
if(passwordvalid && passwordsmatch && currentPassword.val()) { 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(''); currentPassword.val('');
password.val(''); password.val('');
password_confirm.val(''); password_confirm.val('');
password_notify.html(''); password_notify.addClass('hide');
password_confirm_notify.html(''); password_confirm_notify.addClass('hide');
passwordsmatch = false; passwordsmatch = false;
passwordvalid = false; passwordvalid = false;
if(data.err) { if(err) {
app.alertError(data.err); app.alertError(err.error);
return; return;
} }

@ -149,17 +149,19 @@
<div class="control-group"> <div class="control-group">
<label class="control-label" for="inputNewPassword">Password</label> <label class="control-label" for="inputNewPassword">Password</label>
<div class="controls"> <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> </div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="inputNewPasswordAgain">Confirm Password</label> <label class="control-label" for="inputNewPasswordAgain">Confirm Password</label>
<div class="controls"> <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>
</div> </div>
<br/>
<div class="form-actions"> <div class="form-actions">
<a id="changePasswordBtn" href="#" class="btn btn-primary">Change Password</a> <a id="changePasswordBtn" href="#" class="btn btn-primary">Change Password</a>
</div> </div>

@ -37,7 +37,9 @@ var utils = require('./../public/src/utils.js'),
}, },
function(next) { function(next) {
if (email !== undefined) { 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); next(!available ? new Error('Email taken!') : null);
}); });
} else next(); } else next();
@ -209,7 +211,9 @@ var utils = require('./../public/src/utils.js'),
User.getUserField(uid, 'email', function(err, email) { User.getUserField(uid, 'email', function(err, email) {
if(email !== data['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) { if(!available) {
next({error:'Email not available!'}, false); next({error:'Email not available!'}, false);
} else { } else {
@ -272,38 +276,30 @@ var utils = require('./../public/src/utils.js'),
User.isEmailAvailable = function(email, callback) { User.isEmailAvailable = function(email, callback) {
RDB.exists('email:' + email + ':uid' , function(err, exists) { RDB.exists('email:' + email + ':uid' , function(err, exists) {
if(!err) { callback(err, !!exists);
callback(exists !== 1);
return;
} else {
console.log(err);
callback(false);
}
}); });
} }
User.changePassword = function(uid, data, callback) { User.changePassword = function(uid, data, callback) {
if(!utils.isPasswordValid(data.newPassword)) { if(!utils.isPasswordValid(data.newPassword)) {
callback({err:'Invalid password!'}); return callback({error:'Invalid password!'});
return;
} }
User.getUserField(uid, 'password', function(err, user_password) { User.getUserField(uid, 'password', function(err, user_password) {
bcrypt.compare(data.currentPassword, user_password, function(err, res) { bcrypt.compare(data.currentPassword, user_password, function(err, res) {
if(err) { if(err) {
console.log(err); return callback(err);
callback({err:'bcrpyt compare error!'});
return;
} }
if (res) { if (res) {
User.hashPassword(data.newPassword, function(err, hash) { User.hashPassword(data.newPassword, function(err, hash) {
User.setUserField(uid, 'password', hash); User.setUserField(uid, 'password', hash);
callback({err:null}); callback(null);
}); });
} else { } else {
callback({err:'Your current password is not correct!'}); console.log('gg');
callback({error:'Your current password is not correct!'});
} }
}); });
}); });

Loading…
Cancel
Save