From 5370a6f81a14b8ab95f5eb5b19d3b945471997bf Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 17 Feb 2017 08:05:32 -0800 Subject: [PATCH] A few more changes from display to username. --- client/coral-framework/translations.json | 6 +++--- errors.js | 12 ++++++------ routes/api/account/index.js | 2 +- services/users.js | 10 +++++----- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/client/coral-framework/translations.json b/client/coral-framework/translations.json index 5e6a307e4..2884178b6 100644 --- a/client/coral-framework/translations.json +++ b/client/coral-framework/translations.json @@ -25,7 +25,7 @@ "EMAIL_IN_USE": "Email address already in use", "EMAIL_USERNAME_IN_USE": "Email address or username already in use", "USERNAME_IN_USE": "Username already in use", - "DISPLAY_NAME_REQUIRED": "Must input a username", + "USERNAME_REQUIRED": "Must input a username", "NO_SPECIAL_CHARACTERS": "Usernames can contain letters, numbers and _ only", "PROFANITY_ERROR": "Usernames must not contain profanity. Please contact the administrator if you believe this to be in error.", "NOT_AUTHORIZED": "Not authorized.", @@ -51,9 +51,9 @@ "PASSWORD_REQUIRED": "Debe ingresar una contraseña", "PASSWORD_LENGTH": "La contraseña es muy corta", "EMAIL_IN_USE": "La dirección de correo electrónico se encuentra en uso", - "EMAIL_DISPLAY_NAME_IN_USE": "Correo o Nombre en uso.", + "EMAIL_USERNAME_IN_USE": "Correo o Nombre en uso.", "USERNAME_IN_USE": "Nombre en uso.", - "DISPLAY_NAME_REQUIRED": "Debe ingresar un nombre", + "USERNAME_REQUIRED": "Debe ingresar un nombre", "NO_SPECIAL_CHARACTERS": "Los nombres pueden contener letras, números y _", "PROFANITY_ERROR": "Los nombres no pueden contener blasfemias. Por favor contacte al administrador si cree que esto es un error", "NOT_AUTHORIZED": "Acción no autorizada.", diff --git a/errors.js b/errors.js index 9bfa200da..0c473d59c 100644 --- a/errors.js +++ b/errors.js @@ -54,8 +54,8 @@ const ErrEmailTaken = new APIError('Email address already in use', { status: 400 }); -const ErrDisplayTaken = new APIError('Username already in use', { - translation_key: 'DISPLAYNAME_IN_USE', +const ErrUsernameTaken = new APIError('Username already in use', { + translation_key: 'USERNAME_IN_USE', status: 400 }); @@ -64,8 +64,8 @@ const ErrSpecialChars = new APIError('No special characters are allowed in a use status: 400 }); -const ErrMissingDisplay = new APIError('A username is required to create a user', { - translation_key: 'DISPLAY_NAME_REQUIRED', +const ErrMissingUsername = new APIError('A username is required to create a user', { + translation_key: 'USERNAME_REQUIRED', status: 400 }); @@ -157,9 +157,9 @@ module.exports = { ErrMissingToken, ErrEmailTaken, ErrSpecialChars, - ErrMissingDisplay, + ErrMissingUsername, ErrContainsProfanity, - ErrDisplayTaken, + ErrUsernameTaken, ErrAssetCommentingClosed, ErrNotFound, ErrInvalidAssetURL, diff --git a/routes/api/account/index.js b/routes/api/account/index.js index 3de9d41c3..68befd665 100644 --- a/routes/api/account/index.js +++ b/routes/api/account/index.js @@ -123,7 +123,7 @@ router.put('/username', authorization.needed(), (req, res, next) => { }) .catch(error => { if (error.code === 11000) { - next(errors.ErrDisplayTaken); + next(errors.ErrUsernameTake); } else { next(error); } diff --git a/services/users.js b/services/users.js index a319cebe2..df9536525 100644 --- a/services/users.js +++ b/services/users.js @@ -123,7 +123,7 @@ module.exports = class UsersService { if (user) { return user; } - + let username = UsersService.castUsername(displayName); // The user was not found, lets create them! @@ -180,7 +180,7 @@ module.exports = class UsersService { const onlyLettersNumbersUnderscore = /^[A-Za-z0-9_]+$/; if (!username) { - return Promise.reject(errors.ErrMissingDisplay); + return Promise.reject(errors.ErrMissingUsername); } if (!onlyLettersNumbersUnderscore.test(username)) { @@ -220,14 +220,14 @@ module.exports = class UsersService { * @param {String} username name of the display user * @param {Function} done callback */ - static createLocalUser(email, password, displayname) { + static createLocalUser(email, password, username) { if (!email) { return Promise.reject(errors.ErrMissingEmail); } email = email.toLowerCase().trim(); - let username = displayname.trim(); + username = username.trim(); return Promise.all([ UsersService.isValidUsername(username), @@ -257,7 +257,7 @@ module.exports = class UsersService { if (err) { if (err.code === 11000) { if (err.message.match('Username')) { - return reject(errors.ErrDisplayTaken); + return reject(errors.ErrUsernameTake); } return reject(errors.ErrEmailTaken); }