diff --git a/public/language/en_GB/user.json b/public/language/en_GB/user.json index 110dd9698e..1ca6651efb 100644 --- a/public/language/en_GB/user.json +++ b/public/language/en_GB/user.json @@ -38,6 +38,7 @@ "change_password_success": "Your password is updated!", "confirm_password": "Confirm Password", "password": "Password", + "username_taken_workaround": "The username you requested was already taken, so we have altered it slightly. You are now known as %1", "upload_picture": "Upload picture", "upload_a_picture": "Upload a picture", diff --git a/src/notifications.js b/src/notifications.js index 945b7233c1..7524816d16 100644 --- a/src/notifications.js +++ b/src/notifications.js @@ -3,11 +3,13 @@ var async = require('async'), winston = require('winston'), cron = require('cron').CronJob, + nconf = require('nconf'), db = require('./database'), utils = require('../public/src/utils'), events = require('./events'), - User = require('./user'); + User = require('./user'), + meta = require('./meta'); (function(Notifications) { @@ -29,14 +31,22 @@ var async = require('async'), if (exists) { db.sortedSetRank('uid:' + uid + ':notifications:read', nid, function(err, rank) { - db.getObjectFields('notifications:' + nid, ['nid', 'from', 'text', 'importance', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) { + db.getObjectFields('notifications:' + nid, ['nid', 'from', 'text', 'image', 'importance', 'score', 'path', 'datetime', 'uniqueId'], function(err, notification) { notification.read = rank !== null ? true:false; - if (notification.from) { + if (notification.from && !notification.image) { User.getUserField(notification.from, 'picture', function(err, picture) { notification.image = picture; callback(notification); }); + } else if (notification.image) { + switch(notification.image) { + case 'brand:logo': + notification.image = meta.config['brand:logo'] || nconf.get('relative_path') + '/logo.png'; + break; + } + + callback(notification); } else { callback(notification); } diff --git a/src/user/create.js b/src/user/create.js index 3bbfe9e9c7..87c90e4076 100644 --- a/src/user/create.js +++ b/src/user/create.js @@ -1,11 +1,13 @@ 'use strict'; var async = require('async'), - db = require('./../database'), - utils = require('./../../public/src/utils'), + db = require('../database'), + utils = require('../../public/src/utils'), validator = require('validator'), - plugins = require('./../plugins'), - groups = require('./../groups'); + plugins = require('../plugins'), + groups = require('../groups'), + notifications = require('../notifications'), + translator = require('../../public/src/translator'); module.exports = function(User) { @@ -45,7 +47,23 @@ module.exports = function(User) { if (err) { return next(err); } - next(exists ? new Error('[[error:username-taken]]') : null); + if (exists) { + async.forever(function(next) { + // Append a random number to the username + var newUsername = userData.username + (Math.floor(Math.random() * 255) + 1); + User.exists(newUsername, function(err, exists) { + if (!exists) { + next(newUsername); + } else { + next(); + } + }); + }, function(username) { + next(null, username); + }); + } else { + next(); + } }); }, function(next) { @@ -71,6 +89,12 @@ module.exports = function(User) { } userData = results[results.length - 1]; + // If a new username was picked... + if (results[3]) { + userData.username = results[3]; + userData.userslug = utils.slugify(results[3]); + } + db.incrObjectField('global', 'nextUid', function(err, uid) { if(err) { return callback(err); @@ -125,6 +149,19 @@ module.exports = function(User) { groups.join('registered-users', uid); + // If their username was automatically changed... + if (results[3]) { + translator.translate('[[user:username_taken_workaround, ' + userData.username + ']]', function(notifText) { + notifications.create({ + text: notifText, + picture: 'brand:logo', + datetime: Date.now() + }, function(nid) { + notifications.push(nid, uid); + }); + }); + } + if (password) { User.hashPassword(password, function(err, hash) { if(err) {