Merge branch 'master' into the-answer-is-42

This commit is contained in:
Riley Davis
2017-02-16 13:34:31 -07:00
committed by GitHub
2 changed files with 8 additions and 10 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ const ErrEmailTaken = new APIError('Email address already in use', {
status: 400 status: 400
}); });
const ErrDisplayTaken = new APIError('Display name already in use', { const ErrDisplayTaken = new APIError('Username already in use', {
translation_key: 'DISPLAYNAME_IN_USE', translation_key: 'DISPLAYNAME_IN_USE',
status: 400 status: 400
}); });
+7 -9
View File
@@ -99,8 +99,8 @@ module.exports = class UsersService {
.then(() => dstUser.save()); .then(() => dstUser.save());
} }
static castDisplayName(displayName) { static castUsername(username) {
return displayName.replace(/ /g, '_').replace(/[^a-zA-Z_]/g, ''); return username.replace(/ /g, '_').replace(/[^a-zA-Z_]/g, '');
} }
/** /**
@@ -109,7 +109,7 @@ module.exports = class UsersService {
* @param {Object} profile - User social/external profile * @param {Object} profile - User social/external profile
* @param {Function} done [description] * @param {Function} done [description]
*/ */
static findOrCreateExternalUser({id, provider, displayName}) { static findOrCreateExternalUser({id, provider, displayname}) {
return UserModel return UserModel
.findOne({ .findOne({
profiles: { profiles: {
@@ -124,9 +124,7 @@ module.exports = class UsersService {
return user; return user;
} }
// TODO: remove displayName reference when we have steps in the FE to handle let username = UsersService.castUsername(displayname);
// the username create flow.
let username = UsersService.castDisplayName(displayName);
// The user was not found, lets create them! // The user was not found, lets create them!
user = new UserModel({ user = new UserModel({
@@ -178,7 +176,7 @@ module.exports = class UsersService {
* @param {Boolean} checkAgainstWordlist enables cheching against the wordlist * @param {Boolean} checkAgainstWordlist enables cheching against the wordlist
* @return {Promise} * @return {Promise}
*/ */
static isValidDisplayName(username, checkAgainstWordlist = true) { static isValidUserName(username, checkAgainstWordlist = true) {
const onlyLettersNumbersUnderscore = /^[A-Za-z0-9_]+$/; const onlyLettersNumbersUnderscore = /^[A-Za-z0-9_]+$/;
if (!username) { if (!username) {
@@ -232,7 +230,7 @@ module.exports = class UsersService {
username = username.trim(); username = username.trim();
return Promise.all([ return Promise.all([
UsersService.isValidDisplayName(username), UsersService.isValidUserName(username),
UsersService.isValidPassword(password) UsersService.isValidPassword(password)
]) ])
.then(() => { // username is valid .then(() => { // username is valid
@@ -258,7 +256,7 @@ module.exports = class UsersService {
user.save((err) => { user.save((err) => {
if (err) { if (err) {
if (err.code === 11000) { if (err.code === 11000) {
if (err.message.match('username')) { if (err.message.match('Username')) {
return reject(errors.ErrDisplayTaken); return reject(errors.ErrDisplayTaken);
} }
return reject(errors.ErrEmailTaken); return reject(errors.ErrEmailTaken);