From 825e4cca5acb1221f4f38acfe1b293ac02e92764 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 8 Jan 2014 16:11:47 -0500 Subject: [PATCH 1/3] closes #744 --- public/src/forum/category.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/src/forum/category.js b/public/src/forum/category.js index 2a2fb4705b..f084ef17ab 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -53,7 +53,7 @@ define(['composer'], function(composer) { li.setAttribute('data-pid', posts[i].pid); - li.innerHTML = '' + + li.innerHTML = '' + '' + ''+ posts[i].username + '' + '

' + From e07c848da77f12a0822a7f5268ecc316c508582b Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 8 Jan 2014 16:30:27 -0500 Subject: [PATCH 2/3] closes #737 --- public/src/utils.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/src/utils.js b/public/src/utils.js index 67a5aed47d..8f6e51d59d 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -102,6 +102,7 @@ str = XRegExp.replace(str, invalidChars, '-'); str = str.replace(/\s+/g, '-') // collapse whitespace and replace by - str = str.replace(/-+/g, '-'); // collapse dashes + str = str.replace(/-$/g, ''); return str; }, From 176ac54cdfc82b12790a9b18c3baafa7ca6a7907 Mon Sep 17 00:00:00 2001 From: Baris Soner Usakli Date: Wed, 8 Jan 2014 21:19:32 -0500 Subject: [PATCH 3/3] closes #745 --- public/language/en/user.json | 1 + public/src/forum/accountedit.js | 1 + public/templates/accountedit.tpl | 8 +++ src/user.js | 99 ++++++++++++++++++++++++-------- 4 files changed, 84 insertions(+), 25 deletions(-) diff --git a/public/language/en/user.json b/public/language/en/user.json index 10e7772796..dc7412735a 100644 --- a/public/language/en/user.json +++ b/public/language/en/user.json @@ -1,6 +1,7 @@ { "banned": "Banned", "offline": "Offline", + "username": "User Name", "email": "Email", "fullname": "Full Name", "website": "Website", diff --git a/public/src/forum/accountedit.js b/public/src/forum/accountedit.js index 7ec546521c..e86d785945 100644 --- a/public/src/forum/accountedit.js +++ b/public/src/forum/accountedit.js @@ -15,6 +15,7 @@ define(['forum/accountheader', 'uploader'], function(header, uploader) { var userData = { uid: $('#inputUID').val(), + username: $('#inputUsername').val(), email: $('#inputEmail').val(), fullname: $('#inputFullname').val(), website: $('#inputWebsite').val(), diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl index 09b1cc5461..b511bf5917 100644 --- a/public/templates/accountedit.tpl +++ b/public/templates/accountedit.tpl @@ -48,6 +48,14 @@

+ +
+ +
+ +
+
+
diff --git a/src/user.js b/src/user.js index 2cabdf8180..d45bc57b96 100644 --- a/src/user.js +++ b/src/user.js @@ -184,7 +184,7 @@ var bcrypt = require('bcrypt'), 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 = { success: false }; @@ -205,38 +205,66 @@ var bcrypt = require('bcrypt'), } User.getUserField(uid, 'email', function(err, email) { - if (email !== data.email) { - User.isEmailAvailable(data.email, function(err, available) { - if (err) { - return next(err, null); - } - if (!available) { - next({ - error: 'Email not available!' - }, false); - } else { - next(null, true); - } - }); - } else { - next(null, true); + if(email === data.email) { + return next(null, true); } + + User.isEmailAvailable(data.email, function(err, available) { + if (err) { + return next(err, null); + } + + if (!available) { + next({ + error: 'Email not available!' + }, false); + } else { + next(null, true); + } + }); }); } - async.series([isSignatureValid, isEmailAvailable], function(err, results) { - if (err) { - callback(err, returnData); - } else { - async.each(fields, updateField, function(err) { - if (err) { - callback(err, returnData); + 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 { - returnData.success = true; - callback(null, returnData); + next(null, true); } }); + }); + } + + async.series([isSignatureValid, isEmailAvailable, isUsernameAvailable], function(err, results) { + if (err) { + return callback(err, returnData); } + + async.each(fields, updateField, function(err) { + if (err) { + return callback(err, returnData); + } + + returnData.success = true; + callback(null, returnData); + }); }); function updateField(field, next) { @@ -269,6 +297,27 @@ var bcrypt = require('bcrypt'), events.logEmailChange(uid, userData.email, data.email); 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; } else if (field === 'signature') { data[field] = S(data[field]).stripTags().s;