From 3166692d4e3470ffd8f2cec2651542976a598cf0 Mon Sep 17 00:00:00 2001 From: gaba Date: Thu, 16 Feb 2017 15:16:54 -0800 Subject: [PATCH 1/6] Rename everywhere to username. --- bin/cli-setup | 2 +- bin/cli-users | 2 +- client/coral-embed-stream/src/Embed.js | 4 +-- client/coral-framework/actions/auth.js | 26 +++++++-------- client/coral-framework/constants/auth.js | 14 ++++---- client/coral-framework/constants/user.js | 2 +- client/coral-framework/reducers/auth.js | 19 ++++++----- client/coral-framework/translations.json | 12 ++++--- ...yNameDialog.js => CreateUsernameDialog.js} | 8 ++--- ...ontainer.js => ChangeUsernameContainer.js} | 32 +++++++++---------- errors.js | 7 ++++ services/setup.js | 2 +- services/users.js | 6 ++-- test/e2e/pages/embedStreamPage.js | 4 +-- 14 files changed, 75 insertions(+), 65 deletions(-) rename client/coral-sign-in/components/{CreateDisplayNameDialog.js => CreateUsernameDialog.js} (84%) rename client/coral-sign-in/containers/{ChangeDisplayNameContainer.js => ChangeUsernameContainer.js} (74%) diff --git a/bin/cli-setup b/bin/cli-setup index 7985bf220..086c473d5 100755 --- a/bin/cli-setup +++ b/bin/cli-setup @@ -120,7 +120,7 @@ const performSetup = () => { message: 'Username', filter: (username) => { return UsersService - .isValidDisplayName(username, false) + .isValidUsername(username, false) .catch((err) => { throw err.message; }); diff --git a/bin/cli-users b/bin/cli-users index 473c07d9c..fccb4b8bb 100755 --- a/bin/cli-users +++ b/bin/cli-users @@ -79,7 +79,7 @@ function getUserCreateAnswers(options) { message: 'Username', filter: (username) => { return UsersService - .isValidDisplayName(username) + .isValidUsername(username) .catch((err) => { throw err.message; }); diff --git a/client/coral-embed-stream/src/Embed.js b/client/coral-embed-stream/src/Embed.js index f15def5d3..8b420836e 100644 --- a/client/coral-embed-stream/src/Embed.js +++ b/client/coral-embed-stream/src/Embed.js @@ -23,7 +23,7 @@ import CommentBox from 'coral-plugin-commentbox/CommentBox'; import UserBox from 'coral-sign-in/components/UserBox'; import SignInContainer from 'coral-sign-in/containers/SignInContainer'; import SuspendedAccount from 'coral-framework/components/SuspendedAccount'; -import ChangeDisplayNameContainer from '../../coral-sign-in/containers/ChangeDisplayNameContainer'; +import ChangeUsernameContainer from '../../coral-sign-in/containers/ChangeUsernameContainer'; import SettingsContainer from 'coral-settings/containers/SettingsContainer'; import RestrictedContent from 'coral-framework/components/RestrictedContent'; import ConfigureStreamContainer from 'coral-configure/containers/ConfigureStreamContainer'; @@ -147,7 +147,7 @@ class Embed extends Component { :

{asset.settings.closedMessage}

} {!loggedIn && } - {loggedIn && user && } + {loggedIn && user && } ({type: actions.SHOW_SIGNIN_DIALOG, offset}); export const hideSignInDialog = () => ({type: actions.HIDE_SIGNIN_DIALOG}); -export const createDisplayNameRequest = () => ({type: actions.CREATE_DISPLAYNAME_REQUEST}); -export const showCreateDisplayNameDialog = () => ({type: actions.SHOW_CREATEDISPLAYNAME_DIALOG}); -export const hideCreateDisplayNameDialog = () => ({type: actions.HIDE_CREATEDISPLAYNAME_DIALOG}); +export const createUsernameRequest = () => ({type: actions.CREATE_USERNAME_REQUEST}); +export const showCreateUsernameDialog = () => ({type: actions.SHOW_CREATEUSERNAME_DIALOG}); +export const hideCreateUsernameDialog = () => ({type: actions.HIDE_CREATEUSERNAME_DIALOG}); -const createDisplayNameSuccess = () => ({type: actions.CREATEDISPLAYNAME_SUCCESS}); -const createDisplayNameFailure = error => ({type: actions.CREATEDISPLAYNAME_FAILURE, error}); +const createUsernameSuccess = () => ({type: actions.CREATEUSERNAME_SUCCESS}); +const createUsernameFailure = error => ({type: actions.CREATEUSERNAME_FAILURE, error}); -export const updateDisplayName = ({username}) => ({type: actions.UPDATE_DISPLAYNAME, username}); +export const updateUsername = ({username}) => ({type: actions.UPDATE_USERNAME, username}); -export const createDisplayName = (userId, formData) => dispatch => { - dispatch(createDisplayNameRequest()); +export const createUsername = (userId, formData) => dispatch => { + dispatch(createUsernameRequest()); coralApi('/account/username', {method: 'PUT', body: formData}) .then(() => { - dispatch(createDisplayNameSuccess()); - dispatch(hideCreateDisplayNameDialog()); - dispatch(updateDisplayName(formData)); + dispatch(createUsernameSuccess()); + dispatch(hideCreateUsernameDialog()); + dispatch(updateUsername(formData)); }) .catch(error => { - dispatch(createDisplayNameFailure(lang.t(`error.${error.message}`))); + dispatch(createUsernameFailure(lang.t(`error.${error.message}`))); }); }; @@ -102,7 +102,7 @@ export const facebookCallback = (err, data) => dispatch => { const user = JSON.parse(data); dispatch(signInFacebookSuccess(user)); dispatch(hideSignInDialog()); - dispatch(showCreateDisplayNameDialog()); + dispatch(showCreateUsernameDialog()); } catch (err) { dispatch(signInFacebookFailure(err)); return; diff --git a/client/coral-framework/constants/auth.js b/client/coral-framework/constants/auth.js index b6ad3d3a1..8ae032f0a 100644 --- a/client/coral-framework/constants/auth.js +++ b/client/coral-framework/constants/auth.js @@ -4,12 +4,12 @@ export const CLEAN_STATE = 'CLEAN_STATE'; export const SHOW_SIGNIN_DIALOG = 'SHOW_SIGNIN_DIALOG'; export const HIDE_SIGNIN_DIALOG = 'HIDE_SIGNIN_DIALOG'; -export const CREATE_DISPLAYNAME_REQUEST = 'CREATE_DISPLAYNAME_REQUEST'; -export const CREATEDISPLAYNAME_SUCCESS = 'CREATEDISPLAYNAME_SUCCESS'; -export const CREATEDISPLAYNAME_FAILURE = 'CREATEDISPLAYNAME_FAILURE'; -export const CREATE_DISPLAYNAME = 'CREATE_DISPLAYNAME'; -export const SHOW_CREATEDISPLAYNAME_DIALOG = 'SHOW_CREATEDISPLAYNAME_DIALOG'; -export const HIDE_CREATEDISPLAYNAME_DIALOG = 'HIDE_CREATEDISPLAYNAME_DIALOG'; +export const CREATE_USERNAME_REQUEST = 'CREATE_USERNAME_REQUEST'; +export const CREATEUSERNAME_SUCCESS = 'CREATEUSERNAME_SUCCESS'; +export const CREATEUSERNAME_FAILURE = 'CREATEUSERNAME_FAILURE'; +export const CREATE_USERNAME = 'CREATE_USERNAME'; +export const SHOW_CREATEUSERNAME_DIALOG = 'SHOW_CREATEUSERNAME_DIALOG'; +export const HIDE_CREATEUSERNAME_DIALOG = 'HIDE_CREATEUSERNAME_DIALOG'; export const FETCH_SIGNUP_REQUEST = 'FETCH_SIGNUP_REQUEST'; export const FETCH_SIGNUP_FAILURE = 'FETCH_SIGNUP_FAILURE'; @@ -44,4 +44,4 @@ export const CHECK_CSRF_TOKEN = 'CHECK_CSRF_TOKEN'; export const VERIFY_EMAIL_REQUEST = 'VERIFY_EMAIL_REQUEST'; export const VERIFY_EMAIL_SUCCESS = 'VERIFY_EMAIL_SUCCESS'; export const VERIFY_EMAIL_FAILURE = 'VERIFY_EMAIL_FAILURE'; -export const UPDATE_DISPLAYNAME = 'UPDATE_DISPLAYNAME'; +export const UPDATE_USERNAME = 'UPDATE_USERNAME'; diff --git a/client/coral-framework/constants/user.js b/client/coral-framework/constants/user.js index 5e0a23d7a..5f040db5b 100644 --- a/client/coral-framework/constants/user.js +++ b/client/coral-framework/constants/user.js @@ -5,4 +5,4 @@ export const COMMENTS_BY_USER_REQUEST = 'COMMENTS_BY_USER_REQUEST'; export const COMMENTS_BY_USER_SUCCESS = 'COMMENTS_BY_USER_SUCCESS'; export const COMMENTS_BY_USER_FAILURE = 'COMMENTS_BY_USER_FAILURE'; export const LOGOUT_SUCCESS = 'LOGOUT_SUCCESS'; -export const UPDATE_DISPLAYNAME = 'UPDATE_DISPLAYNAME'; +export const UPDATE_USERNAME = 'UPDATE_USERNAME'; diff --git a/client/coral-framework/reducers/auth.js b/client/coral-framework/reducers/auth.js index 92e9bb4c2..65cd366eb 100644 --- a/client/coral-framework/reducers/auth.js +++ b/client/coral-framework/reducers/auth.js @@ -7,7 +7,7 @@ const initialState = Map({ isAdmin: false, user: null, showSignInDialog: false, - showCreateDisplayNameDialog: false, + showCreateUsernameDialog: false, view: 'SIGNIN', error: '', passwordRequestSuccess: null, @@ -43,19 +43,19 @@ export default function auth (state = initialState, action) { emailVerificationLoading: false, successSignUp: false })); - case actions.SHOW_CREATEDISPLAYNAME_DIALOG : + case actions.SHOW_CREATEUSERNAME_DIALOG : return state - .set('showCreateDisplayNameDialog', true); - case actions.HIDE_CREATEDISPLAYNAME_DIALOG : + .set('showCreateUsernameDialog', true); + case actions.HIDE_CREATEUSERNAME_DIALOG : return state.merge(Map({ - showCreateDisplayNameDialog: false + showCreateUsernameDialog: false })); - case actions.CREATEDISPLAYNAME_SUCCESS : + case actions.CREATEUSERNAME_SUCCESS : return state.merge(Map({ - showCreateDisplayNameDialog: false, + showCreateUsernameDialog: false, error: '' })); - case actions.CREATEDISPLAYNAME_FAILURE : + case actions.CREATEUSERNAME_FAILURE : return state .set('error', action.error); case actions.CHANGE_VIEW : @@ -130,8 +130,7 @@ export default function auth (state = initialState, action) { return state .set('passwordRequestFailure', 'There was an error sending your password reset email. Please try again soon!') .set('passwordRequestSuccess', null); - case actions.UPDATE_DISPLAYNAME: - console.log('Action', action); + case actions.UPDATE_USERNAME: return state .setIn(['user', 'username'], action.username); case actions.VERIFY_EMAIL_FAILURE: diff --git a/client/coral-framework/translations.json b/client/coral-framework/translations.json index d3cf71f6e..07780e602 100644 --- a/client/coral-framework/translations.json +++ b/client/coral-framework/translations.json @@ -24,10 +24,12 @@ "PASSWORD_LENGTH": "Password is too short", "EMAIL_IN_USE": "Email address already in use", "EMAIL_DISPLAY_NAME_IN_USE": "Email address or username already in use", - "DISPLAYNAME_IN_USE": "Display name already in use", + "USERNAME_IN_USE": "Display name already in use", "DISPLAY_NAME_REQUIRED": "Must input a username", "NO_SPECIAL_CHARACTERS": "Display names can contain letters, numbers and _ only", - "PROFANITY_ERROR": "Display names must not contain profanity. Please contact the administrator if you believe this to be in error." + "PROFANITY_ERROR": "Display names must not contain profanity. Please contact the administrator if you believe this to be in error.", + "NOT_AUTHORIZED": "Not authorized.", + "EDIT_USERNAME_NOT_AUTHORIZED": "You do not have permission to update your username." } }, "es": { @@ -50,10 +52,12 @@ "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.", - "DISPLAYNAME_IN_USE": "Nombre en uso.", + "USERNAME_IN_USE": "Nombre en uso.", "DISPLAY_NAME_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" + "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.", + "EDIT_USERNAME_NOT_AUTHORIZED": "No tiene permiso para editar el nombre de usuario." } } } diff --git a/client/coral-sign-in/components/CreateDisplayNameDialog.js b/client/coral-sign-in/components/CreateUsernameDialog.js similarity index 84% rename from client/coral-sign-in/components/CreateDisplayNameDialog.js rename to client/coral-sign-in/components/CreateUsernameDialog.js index 5b04e335d..d245b38ac 100644 --- a/client/coral-sign-in/components/CreateDisplayNameDialog.js +++ b/client/coral-sign-in/components/CreateUsernameDialog.js @@ -8,10 +8,10 @@ import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../translations'; const lang = new I18n(translations); -const CreateDisplayNameDialog = ({open, handleClose, offset, formData, handleSubmitDisplayName, handleChange, ...props}) => ( +const CreateUsernameDialog = ({open, handleClose, offset, formData, handleSubmitUsername, handleChange, ...props}) => ( { props.auth.error && {props.auth.error} } -
+ ); -export default CreateDisplayNameDialog; +export default CreateUsernameDialog; diff --git a/client/coral-sign-in/containers/ChangeDisplayNameContainer.js b/client/coral-sign-in/containers/ChangeUsernameContainer.js similarity index 74% rename from client/coral-sign-in/containers/ChangeDisplayNameContainer.js rename to client/coral-sign-in/containers/ChangeUsernameContainer.js index 625985b63..33ae63614 100644 --- a/client/coral-sign-in/containers/ChangeDisplayNameContainer.js +++ b/client/coral-sign-in/containers/ChangeUsernameContainer.js @@ -4,21 +4,21 @@ import {connect} from 'react-redux'; import validate from 'coral-framework/helpers/validate'; import errorMsj from 'coral-framework/helpers/error'; -import CreateDisplayNameDialog from '../components/CreateDisplayNameDialog'; +import CreateUsernameDialog from '../components/CreateUsernameDialog'; import I18n from 'coral-framework/modules/i18n/i18n'; import translations from '../translations'; const lang = new I18n(translations); import { - showCreateDisplayNameDialog, - hideCreateDisplayNameDialog, + showCreateUsernameDialog, + hideCreateUsernameDialog, invalidForm, validForm, - createDisplayName + createUsername } from '../../coral-framework/actions/auth'; -class ChangeDisplayNameContainer extends Component { +class ChangeUsernameContainer extends Component { initialState = { formData: { username: '', @@ -31,7 +31,7 @@ class ChangeDisplayNameContainer extends Component { super(props); this.state = this.initialState; this.handleChange = this.handleChange.bind(this); - this.handleSubmitDisplayName = this.handleSubmitDisplayName.bind(this); + this.handleSubmitUsername = this.handleSubmitUsername.bind(this); this.handleClose = this.handleClose.bind(this); this.addError = this.addError.bind(this); } @@ -81,13 +81,13 @@ class ChangeDisplayNameContainer extends Component { this.setState({showErrors: show}); } - handleSubmitDisplayName(e) { + handleSubmitUsername(e) { e.preventDefault(); const {errors} = this.state; const {validForm, invalidForm} = this.props; this.displayErrors(); if (this.isCompleted() && !Object.keys(errors).length) { - this.props.createDisplayName(this.props.user.id, this.state.formData); + this.props.createUsername(this.props.user.id, this.state.formData); validForm(); } else { invalidForm(lang.t('createdisplay.checkTheForm')); @@ -95,19 +95,19 @@ class ChangeDisplayNameContainer extends Component { } handleClose() { - this.props.hideCreateDisplayNameDialog(); + this.props.hideCreateUsernameDialog(); } render() { const {loggedIn, auth, offset} = this.props; return (
- ({ }); const mapDispatchToProps = dispatch => ({ - createDisplayName: (userid, formData) => dispatch(createDisplayName(userid, formData)), - showCreateDisplayNameDialog: () => dispatch(showCreateDisplayNameDialog()), - hideCreateDisplayNameDialog: () => dispatch(hideCreateDisplayNameDialog()), + createUsername: (userid, formData) => dispatch(createUsername(userid, formData)), + showCreateUsernameDialog: () => dispatch(showCreateUsernameDialog()), + hideCreateUsernameDialog: () => dispatch(hideCreateUsernameDialog()), invalidForm: error => dispatch(invalidForm(error)), validForm: () => dispatch(validForm()) }); @@ -132,4 +132,4 @@ const mapDispatchToProps = dispatch => ({ export default connect( mapStateToProps, mapDispatchToProps -)(ChangeDisplayNameContainer); +)(ChangeUsernameContainer); diff --git a/errors.js b/errors.js index ee68b67fd..9bfa200da 100644 --- a/errors.js +++ b/errors.js @@ -141,6 +141,12 @@ const ErrInstallLock = new APIError('install lock active', { status: 500 }); +// ErrPermissionUpdateUsername is returned when the user does not have permission to update their username. +const ErrPermissionUpdateUsername = new APIError('You do not have permission to update your username.', { + translation_key: 'EDIT_USERNAME_NOT_AUTHORIZED', + status: 500 +}); + module.exports = { ExtendableError, APIError, @@ -159,6 +165,7 @@ module.exports = { ErrInvalidAssetURL, ErrAuthentication, ErrNotAuthorized, + ErrPermissionUpdateUsername, ErrSettingsInit, ErrInstallLock }; diff --git a/services/setup.js b/services/setup.js index 2bfbc66a0..1f1542d5e 100644 --- a/services/setup.js +++ b/services/setup.js @@ -57,7 +57,7 @@ module.exports = class SetupService { // Verify other properties of the user. return Promise.all([ - UsersService.isValidDisplayName(username, false), + UsersService.isValidUsername(username, false), UsersService.isValidPassword(password), settingsModel.validate() ]); diff --git a/services/users.js b/services/users.js index f715fa9f4..aef30aa75 100644 --- a/services/users.js +++ b/services/users.js @@ -176,7 +176,7 @@ module.exports = class UsersService { * @param {Boolean} checkAgainstWordlist enables cheching against the wordlist * @return {Promise} */ - static isValidUserName(username, checkAgainstWordlist = true) { + static isValidUsername(username, checkAgainstWordlist = true) { const onlyLettersNumbersUnderscore = /^[A-Za-z0-9_]+$/; if (!username) { @@ -230,7 +230,7 @@ module.exports = class UsersService { username = username.trim(); return Promise.all([ - UsersService.isValidUserName(username), + UsersService.isValidUsername(username), UsersService.isValidPassword(password) ]) .then(() => { // username is valid @@ -688,7 +688,7 @@ module.exports = class UsersService { } }).then((result) => { return result.nModified > 0 ? result : - Promise.reject(new Error('You do not have permission to update your username.')); + Promise.reject(errors.ErrPermissionUpdateUsername); }); } }; diff --git a/test/e2e/pages/embedStreamPage.js b/test/e2e/pages/embedStreamPage.js index b25eec419..ca72df1db 100644 --- a/test/e2e/pages/embedStreamPage.js +++ b/test/e2e/pages/embedStreamPage.js @@ -19,7 +19,7 @@ const embedStreamCommands = { .setValue('@signInDialogEmail', user.email) .setValue('@signInDialogPassword', user.pass) .setValue('@signUpDialogConfirmPassword', user.pass) - .setValue('@signUpDialogDisplayName', user.username) + .setValue('@signUpDialogUsername', user.username) .waitForElementVisible('@signUpButton') .click('@signUpButton') .waitForElementVisible('@signInViewTrigger') @@ -95,7 +95,7 @@ module.exports = { signUpDialogConfirmPassword: { selector: '#signInDialog #confirmPassword' }, - signUpDialogDisplayName: { + signUpDialogUsername: { selector: '#signInDialog #username' }, logInButton: { From 4765973a58886a8938551bb33aa8828a5af31b2a Mon Sep 17 00:00:00 2001 From: gaba Date: Thu, 16 Feb 2017 16:07:19 -0800 Subject: [PATCH 2/6] Other small changes and fix bug because displayname instead displayName... --- client/coral-framework/actions/auth.js | 6 +++--- client/coral-framework/constants/auth.js | 4 ++-- client/coral-framework/reducers/auth.js | 4 ++-- services/passport.js | 2 -- services/users.js | 10 +++++----- 5 files changed, 12 insertions(+), 14 deletions(-) diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index 51a06e2d7..7576478c4 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -12,8 +12,8 @@ export const createUsernameRequest = () => ({type: actions.CREATE_USERNAME_REQUE export const showCreateUsernameDialog = () => ({type: actions.SHOW_CREATEUSERNAME_DIALOG}); export const hideCreateUsernameDialog = () => ({type: actions.HIDE_CREATEUSERNAME_DIALOG}); -const createUsernameSuccess = () => ({type: actions.CREATEUSERNAME_SUCCESS}); -const createUsernameFailure = error => ({type: actions.CREATEUSERNAME_FAILURE, error}); +const createUsernameSuccess = () => ({type: actions.CREATE_USERNAME_SUCCESS}); +const createUsernameFailure = error => ({type: actions.CREATE_USERNAME_FAILURE, error}); export const updateUsername = ({username}) => ({type: actions.UPDATE_USERNAME, username}); @@ -95,7 +95,7 @@ export const fetchSignUpFacebook = () => dispatch => { export const facebookCallback = (err, data) => dispatch => { if (err) { - signInFacebookFailure(err); + dispatch(signInFacebookFailure(err)); return; } try { diff --git a/client/coral-framework/constants/auth.js b/client/coral-framework/constants/auth.js index 8ae032f0a..9a217fb43 100644 --- a/client/coral-framework/constants/auth.js +++ b/client/coral-framework/constants/auth.js @@ -5,8 +5,8 @@ export const SHOW_SIGNIN_DIALOG = 'SHOW_SIGNIN_DIALOG'; export const HIDE_SIGNIN_DIALOG = 'HIDE_SIGNIN_DIALOG'; export const CREATE_USERNAME_REQUEST = 'CREATE_USERNAME_REQUEST'; -export const CREATEUSERNAME_SUCCESS = 'CREATEUSERNAME_SUCCESS'; -export const CREATEUSERNAME_FAILURE = 'CREATEUSERNAME_FAILURE'; +export const CREATE_USERNAME_SUCCESS = 'CREATE_USERNAME_SUCCESS'; +export const CREATE_USERNAME_FAILURE = 'CREATE_USERNAME_FAILURE'; export const CREATE_USERNAME = 'CREATE_USERNAME'; export const SHOW_CREATEUSERNAME_DIALOG = 'SHOW_CREATEUSERNAME_DIALOG'; export const HIDE_CREATEUSERNAME_DIALOG = 'HIDE_CREATEUSERNAME_DIALOG'; diff --git a/client/coral-framework/reducers/auth.js b/client/coral-framework/reducers/auth.js index 65cd366eb..f9712c937 100644 --- a/client/coral-framework/reducers/auth.js +++ b/client/coral-framework/reducers/auth.js @@ -50,12 +50,12 @@ export default function auth (state = initialState, action) { return state.merge(Map({ showCreateUsernameDialog: false })); - case actions.CREATEUSERNAME_SUCCESS : + case actions.CREATE_USERNAME_SUCCESS : return state.merge(Map({ showCreateUsernameDialog: false, error: '' })); - case actions.CREATEUSERNAME_FAILURE : + case actions.CREATE_USERNAME_FAILURE : return state .set('error', action.error); case actions.CHANGE_VIEW : diff --git a/services/passport.js b/services/passport.js index d265d9812..229541521 100644 --- a/services/passport.js +++ b/services/passport.js @@ -103,8 +103,6 @@ if (process.env.TALK_FACEBOOK_APP_ID && process.env.TALK_FACEBOOK_APP_SECRET && clientSecret: process.env.TALK_FACEBOOK_APP_SECRET, callbackURL: `${process.env.TALK_ROOT_URL}/api/v1/auth/facebook/callback`, - // TODO: remove displayName reference when we have steps in the FE to handle - // the username create flow. profileFields: ['id', 'displayName', 'picture.type(large)'] }, (accessToken, refreshToken, profile, done) => { UsersService diff --git a/services/users.js b/services/users.js index aef30aa75..a319cebe2 100644 --- a/services/users.js +++ b/services/users.js @@ -109,7 +109,7 @@ module.exports = class UsersService { * @param {Object} profile - User social/external profile * @param {Function} done [description] */ - static findOrCreateExternalUser({id, provider, displayname}) { + static findOrCreateExternalUser({id, provider, displayName}) { return UserModel .findOne({ profiles: { @@ -123,8 +123,8 @@ module.exports = class UsersService { if (user) { return user; } - - let username = UsersService.castUsername(displayname); + + let username = UsersService.castUsername(displayName); // The user was not found, lets create them! user = new UserModel({ @@ -220,14 +220,14 @@ module.exports = class UsersService { * @param {String} username name of the display user * @param {Function} done callback */ - static createLocalUser(email, password, username) { + static createLocalUser(email, password, displayname) { if (!email) { return Promise.reject(errors.ErrMissingEmail); } email = email.toLowerCase().trim(); - username = username.trim(); + let username = displayname.trim(); return Promise.all([ UsersService.isValidUsername(username), From 8502b4397470f7703bae837c23473a66a35d72fe Mon Sep 17 00:00:00 2001 From: David Erwin Date: Fri, 17 Feb 2017 10:04:15 -0500 Subject: [PATCH 3/6] Updating more displayname to username --- client/coral-framework/translations.json | 12 ++++++------ client/coral-sign-in/translations.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/client/coral-framework/translations.json b/client/coral-framework/translations.json index 07780e602..5e6a307e4 100644 --- a/client/coral-framework/translations.json +++ b/client/coral-framework/translations.json @@ -9,13 +9,13 @@ "msg": "Your account is currently suspended because your username has been deemed inappropriate. To restore your account, please enter a new username. You may contact moderator@fakeurl.com for more information.", "label": "New Username", "button": "Submit", - "error": "Display names can contain letters, numbers and _ only" + "error": "Usernames can contain letters, numbers and _ only" }, "error": { "emailNotVerified": "Email address {0} not verified.", "email": "Not a valid E-Mail", "password": "Password must be at least 8 characters", - "username": "Display names can contain letters, numbers and _ only", + "username": "Usernames can contain letters, numbers and _ only", "confirmPassword": "Passwords don't match. Please, check again", "organizationName": "Organization name must only contain letters or numbers.", "emailPasswordError": "Email and/or password combination incorrect.", @@ -23,11 +23,11 @@ "PASSWORD_REQUIRED": "Must input a password", "PASSWORD_LENGTH": "Password is too short", "EMAIL_IN_USE": "Email address already in use", - "EMAIL_DISPLAY_NAME_IN_USE": "Email address or username already in use", - "USERNAME_IN_USE": "Display name 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", - "NO_SPECIAL_CHARACTERS": "Display names can contain letters, numbers and _ only", - "PROFANITY_ERROR": "Display names must not contain profanity. Please contact the administrator if you believe this to be in error.", + "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.", "EDIT_USERNAME_NOT_AUTHORIZED": "You do not have permission to update your username." } diff --git a/client/coral-sign-in/translations.js b/client/coral-sign-in/translations.js index 36ce3fce4..0ac463b1c 100644 --- a/client/coral-sign-in/translations.js +++ b/client/coral-sign-in/translations.js @@ -26,7 +26,7 @@ export default { emailORusernameInUse: 'Email address or Username already in use', requiredField: 'This field is required', passwordsDontMatch: 'Passwords don\'t match.', - specialCharacters: 'Display names can contain letters, numbers and _ only', + specialCharacters: 'Usernames can contain letters, numbers and _ only', checkTheForm: 'Invalid Form. Please, check the fields' }, 'createdisplay': { @@ -37,7 +37,7 @@ export default { requiredField: 'Required field', errorCreate: 'Error when changing username', checkTheForm: 'Invalid Form. Please, check the fields', - specialCharacters: 'Display names can contain letters, numbers and _ only' + specialCharacters: 'Usernames can contain letters, numbers and _ only' }, }, es: { From 5370a6f81a14b8ab95f5eb5b19d3b945471997bf Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 17 Feb 2017 08:05:32 -0800 Subject: [PATCH 4/6] 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); } From 3bfac591b38e2336565590625d90b07bd7e7f4b2 Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 17 Feb 2017 08:20:27 -0800 Subject: [PATCH 5/6] An N was missing... --- routes/api/account/index.js | 2 +- services/users.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/api/account/index.js b/routes/api/account/index.js index 68befd665..4eab8b920 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.ErrUsernameTake); + next(errors.ErrUsernameTaken); } else { next(error); } diff --git a/services/users.js b/services/users.js index df9536525..b09a7d399 100644 --- a/services/users.js +++ b/services/users.js @@ -257,7 +257,7 @@ module.exports = class UsersService { if (err) { if (err.code === 11000) { if (err.message.match('Username')) { - return reject(errors.ErrUsernameTake); + return reject(errors.ErrUsernameTaken); } return reject(errors.ErrEmailTaken); } From dd3435fffe66ceb7f01f8a03543056ad6b0c2357 Mon Sep 17 00:00:00 2001 From: gaba Date: Fri, 17 Feb 2017 08:42:48 -0800 Subject: [PATCH 6/6] Replace with translation_key to manage error translation. --- client/coral-framework/actions/auth.js | 4 ++-- client/coral-sign-in/translations.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/coral-framework/actions/auth.js b/client/coral-framework/actions/auth.js index 7576478c4..8618cf1d3 100644 --- a/client/coral-framework/actions/auth.js +++ b/client/coral-framework/actions/auth.js @@ -26,7 +26,7 @@ export const createUsername = (userId, formData) => dispatch => { dispatch(updateUsername(formData)); }) .catch(error => { - dispatch(createUsernameFailure(lang.t(`error.${error.message}`))); + dispatch(createUsernameFailure(lang.t(`error.${error.translation_key}`))); }); }; @@ -123,7 +123,7 @@ export const fetchSignUp = (formData, redirectUri) => (dispatch) => { dispatch(signUpSuccess(user)); }) .catch(error => { - dispatch(signUpFailure(lang.t(`error.${error.message}`))); + dispatch(signUpFailure(lang.t(`error.${error.translation_key}`))); }); }; diff --git a/client/coral-sign-in/translations.js b/client/coral-sign-in/translations.js index 0ac463b1c..a2bb60819 100644 --- a/client/coral-sign-in/translations.js +++ b/client/coral-sign-in/translations.js @@ -38,7 +38,7 @@ export default { errorCreate: 'Error when changing username', checkTheForm: 'Invalid Form. Please, check the fields', specialCharacters: 'Usernames can contain letters, numbers and _ only' - }, + } }, es: { 'signIn': {