v1.18.x
Baris Soner Usakli 11 years ago
parent e07c848da7
commit 176ac54cdf

@ -1,6 +1,7 @@
{ {
"banned": "Banned", "banned": "Banned",
"offline": "Offline", "offline": "Offline",
"username": "User Name",
"email": "Email", "email": "Email",
"fullname": "Full Name", "fullname": "Full Name",
"website": "Website", "website": "Website",

@ -15,6 +15,7 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) {
var userData = { var userData = {
uid: $('#inputUID').val(), uid: $('#inputUID').val(),
username: $('#inputUsername').val(),
email: $('#inputEmail').val(), email: $('#inputEmail').val(),
fullname: $('#inputFullname').val(), fullname: $('#inputFullname').val(),
website: $('#inputWebsite').val(), website: $('#inputWebsite').val(),

@ -48,6 +48,14 @@
<div class="col-md-5"> <div class="col-md-5">
<div> <div>
<form class='form-horizontal'> <form class='form-horizontal'>
<div class="control-group">
<label class="control-label" for="inputUsername">[[user:username]]</label>
<div class="controls">
<input class="form-control" type="text" id="inputUsername" placeholder="Username" value="{username}">
</div>
</div>
<div class="control-group"> <div class="control-group">
<label class="control-label" for="inputEmail">[[user:email]]</label> <label class="control-label" for="inputEmail">[[user:email]]</label>
<div class="controls"> <div class="controls">

@ -184,7 +184,7 @@ var bcrypt = require('bcrypt'),
User.updateProfile = function(uid, data, callback) { User.updateProfile = function(uid, data, callback) {
var fields = ['email', 'fullname', 'website', 'location', 'birthday', 'signature']; var fields = ['username', 'email', 'fullname', 'website', 'location', 'birthday', 'signature'];
var returnData = { var returnData = {
success: false success: false
}; };
@ -205,11 +205,15 @@ var bcrypt = require('bcrypt'),
} }
User.getUserField(uid, 'email', function(err, email) { User.getUserField(uid, 'email', function(err, email) {
if (email !== data.email) { if(email === data.email) {
return next(null, true);
}
User.isEmailAvailable(data.email, function(err, available) { User.isEmailAvailable(data.email, function(err, available) {
if (err) { if (err) {
return next(err, null); return next(err, null);
} }
if (!available) { if (!available) {
next({ next({
error: 'Email not available!' error: 'Email not available!'
@ -218,25 +222,49 @@ var bcrypt = require('bcrypt'),
next(null, true); next(null, true);
} }
}); });
});
}
function isUsernameAvailable(next) {
User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
var userslug = utils.slugify(data.username);
if(userslug === userData.userslug) {
return next(null, true);
}
if(!utils.isUserNameValid(data.username) || !userslug) {
return next({
error: 'Invalid Username!'
}, false);
}
User.exists(userslug, function(exists) {
if(exists) {
next({
error: 'Username not available!'
}, false);
} else { } else {
next(null, true); next(null, true);
} }
}); });
});
} }
async.series([isSignatureValid, isEmailAvailable], function(err, results) { async.series([isSignatureValid, isEmailAvailable, isUsernameAvailable], function(err, results) {
if (err) { if (err) {
callback(err, returnData); return callback(err, returnData);
} else { }
async.each(fields, updateField, function(err) { async.each(fields, updateField, function(err) {
if (err) { if (err) {
callback(err, returnData); return callback(err, returnData);
} else { }
returnData.success = true; returnData.success = true;
callback(null, returnData); callback(null, returnData);
}
}); });
}
}); });
function updateField(field, next) { function updateField(field, next) {
@ -269,6 +297,27 @@ var bcrypt = require('bcrypt'),
events.logEmailChange(uid, userData.email, data.email); events.logEmailChange(uid, userData.email, data.email);
next(); next();
}); });
return;
} else if (field === 'username') {
User.getUserFields(uid, ['username', 'userslug'], function(err, userData) {
var userslug = utils.slugify(data.username);
if(data.username !== userData.username) {
User.setUserField(uid, 'username', data.username);
db.deleteObjectField('username:uid', userData.username);
db.setObjectField('username:uid', data.username, uid);
}
if(userslug !== userData.userslug) {
User.setUserField(uid, 'userslug', userslug);
db.deleteObjectField('userslug:uid', userData.userslug);
db.setObjectField('userslug:uid', userslug, uid);
}
next();
});
return; return;
} else if (field === 'signature') { } else if (field === 'signature') {
data[field] = S(data[field]).stripTags().s; data[field] = S(data[field]).stripTags().s;

Loading…
Cancel
Save