closes #1637
parent
36bfe30425
commit
7854e67b7b
@ -0,0 +1,39 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* globals define, ajaxify, socket, app */
|
||||||
|
|
||||||
|
define('forum/account/edit/email', ['forum/account/header'], function(header) {
|
||||||
|
var AccountEditEmail = {};
|
||||||
|
|
||||||
|
AccountEditEmail.init = function() {
|
||||||
|
header.init();
|
||||||
|
|
||||||
|
$('#submitBtn').on('click', function () {
|
||||||
|
var userData = {
|
||||||
|
uid: $('#inputUID').val(),
|
||||||
|
email: $('#inputNewEmail').val(),
|
||||||
|
password: $('#inputCurrentPassword').val()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!userData.email) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var btn = $(this);
|
||||||
|
btn.addClass('disabled').find('i').removeClass('hide');
|
||||||
|
|
||||||
|
socket.emit('user.changeUsernameEmail', userData, function(err) {
|
||||||
|
btn.removeClass('disabled').find('i').addClass('hide');
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
ajaxify.go('user/' + ajaxify.data.userslug);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return AccountEditEmail;
|
||||||
|
});
|
@ -0,0 +1,116 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* globals define, ajaxify, socket, app, config, utils */
|
||||||
|
|
||||||
|
define('forum/account/edit/password', ['forum/account/header', 'translator'], function(header, translator) {
|
||||||
|
var AccountEditPassword = {};
|
||||||
|
|
||||||
|
AccountEditPassword.init = function() {
|
||||||
|
header.init();
|
||||||
|
|
||||||
|
handlePasswordChange();
|
||||||
|
};
|
||||||
|
|
||||||
|
function handlePasswordChange() {
|
||||||
|
var currentPassword = $('#inputCurrentPassword');
|
||||||
|
var password_notify = $('#password-notify');
|
||||||
|
var password_confirm_notify = $('#password-confirm-notify');
|
||||||
|
var password = $('#inputNewPassword');
|
||||||
|
var password_confirm = $('#inputNewPasswordAgain');
|
||||||
|
var passwordvalid = false;
|
||||||
|
var passwordsmatch = false;
|
||||||
|
|
||||||
|
function onPasswordChanged() {
|
||||||
|
if (password.val().length < config.minimumPasswordLength) {
|
||||||
|
showError(password_notify, '[[user:change_password_error_length]]');
|
||||||
|
passwordvalid = false;
|
||||||
|
} else if (!utils.isPasswordValid(password.val())) {
|
||||||
|
showError(password_notify, '[[user:change_password_error]]');
|
||||||
|
passwordvalid = false;
|
||||||
|
} else {
|
||||||
|
showSuccess(password_notify);
|
||||||
|
passwordvalid = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function onPasswordConfirmChanged() {
|
||||||
|
if (password.val() !== password_confirm.val()) {
|
||||||
|
showError(password_confirm_notify, '[[user:change_password_error_match]]');
|
||||||
|
passwordsmatch = false;
|
||||||
|
} else {
|
||||||
|
if (password.val()) {
|
||||||
|
showSuccess(password_confirm_notify);
|
||||||
|
} else {
|
||||||
|
password_confirm_notify.parent().removeClass('alert-success alert-danger');
|
||||||
|
password_confirm_notify.children().show();
|
||||||
|
password_confirm_notify.find('.msg').html('');
|
||||||
|
}
|
||||||
|
|
||||||
|
passwordsmatch = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
password.on('blur', onPasswordChanged);
|
||||||
|
password_confirm.on('blur', onPasswordConfirmChanged);
|
||||||
|
|
||||||
|
$('#changePasswordBtn').on('click', function() {
|
||||||
|
onPasswordChanged();
|
||||||
|
onPasswordConfirmChanged();
|
||||||
|
|
||||||
|
var btn = $(this);
|
||||||
|
if ((passwordvalid && passwordsmatch) || app.user.isAdmin) {
|
||||||
|
btn.addClass('disabled').find('i').removeClass('hide');
|
||||||
|
socket.emit('user.changePassword', {
|
||||||
|
'currentPassword': currentPassword.val(),
|
||||||
|
'newPassword': password.val(),
|
||||||
|
'uid': ajaxify.data.theirid
|
||||||
|
}, function(err) {
|
||||||
|
btn.removeClass('disabled').find('i').addClass('hide');
|
||||||
|
currentPassword.val('');
|
||||||
|
password.val('');
|
||||||
|
password_confirm.val('');
|
||||||
|
passwordsmatch = false;
|
||||||
|
passwordvalid = false;
|
||||||
|
|
||||||
|
if (err) {
|
||||||
|
onPasswordChanged();
|
||||||
|
onPasswordConfirmChanged();
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
ajaxify.go('user/' + ajaxify.data.userslug);
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showError(element, msg) {
|
||||||
|
translator.translate(msg, function(msg) {
|
||||||
|
element.find('.error').html(msg).removeClass('hide').siblings().addClass('hide');
|
||||||
|
|
||||||
|
element.parent()
|
||||||
|
.removeClass('alert-success')
|
||||||
|
.addClass('alert-danger');
|
||||||
|
element.show();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function showSuccess(element) {
|
||||||
|
element.find('.success').removeClass('hide').siblings().addClass('hide');
|
||||||
|
element.parent()
|
||||||
|
.removeClass('alert-danger')
|
||||||
|
.addClass('alert-success');
|
||||||
|
element.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
return AccountEditPassword;
|
||||||
|
});
|
@ -0,0 +1,43 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
/* globals define, ajaxify, socket, app, utils, config */
|
||||||
|
|
||||||
|
define('forum/account/edit/username', ['forum/account/header'], function(header) {
|
||||||
|
var AccountEditUsername = {};
|
||||||
|
|
||||||
|
AccountEditUsername.init = function() {
|
||||||
|
header.init();
|
||||||
|
|
||||||
|
$('#submitBtn').on('click', function updateUsername() {
|
||||||
|
var userData = {
|
||||||
|
uid: $('#inputUID').val(),
|
||||||
|
username: $('#inputNewUsername').val(),
|
||||||
|
password: $('#inputCurrentPassword').val()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!userData.username) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var btn = $(this);
|
||||||
|
btn.addClass('disabled').find('i').removeClass('hide');
|
||||||
|
socket.emit('user.changeUsernameEmail', userData, function(err) {
|
||||||
|
btn.removeClass('disabled').find('i').addClass('hide');
|
||||||
|
if (err) {
|
||||||
|
return app.alertError(err.message);
|
||||||
|
}
|
||||||
|
|
||||||
|
var userslug = utils.slugify(userData.username);
|
||||||
|
if (userData.username && userslug && parseInt(userData.uid, 10) === parseInt(app.user.uid, 10)) {
|
||||||
|
$('[component="header/profilelink"]').attr('href', config.relative_path + '/user/' + userslug);
|
||||||
|
$('[component="header/username"]').text(userData.username);
|
||||||
|
}
|
||||||
|
|
||||||
|
ajaxify.go('user/' + userslug);
|
||||||
|
});
|
||||||
|
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
return AccountEditUsername;
|
||||||
|
});
|
@ -0,0 +1,28 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
var nconf = require('nconf');
|
||||||
|
|
||||||
|
var db = require('../database');
|
||||||
|
var Password = require('../password');
|
||||||
|
|
||||||
|
module.exports = function(User) {
|
||||||
|
|
||||||
|
User.hashPassword = function(password, callback) {
|
||||||
|
if (!password) {
|
||||||
|
return callback(null, password);
|
||||||
|
}
|
||||||
|
|
||||||
|
Password.hash(nconf.get('bcrypt_rounds') || 12, password, callback);
|
||||||
|
};
|
||||||
|
|
||||||
|
User.isPasswordCorrect = function(uid, password, callback) {
|
||||||
|
db.getObjectField('user:' + uid, 'password', function(err, hashedPassword) {
|
||||||
|
if (err || !hashedPassword) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
Password.compare(password || '', hashedPassword, callback);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
};
|
Loading…
Reference in New Issue