diff --git a/app/locale/en.coffee b/app/locale/en.coffee index 29ce12d0e..9aee76dfa 100644 --- a/app/locale/en.coffee +++ b/app/locale/en.coffee @@ -287,6 +287,7 @@ email_good: "Email looks good!" name_taken: "Username already taken! Try {{suggestedName}}?" name_available: "Username available!" + name_is_email: "Username may not be an email" choose_type: "Choose your account type:" teacher_type_1: "Teach programming using CodeCombat!" teacher_type_2: "Set up your class" diff --git a/app/views/account/AccountSettingsView.coffee b/app/views/account/AccountSettingsView.coffee index c29034d93..70c945b8c 100644 --- a/app/views/account/AccountSettingsView.coffee +++ b/app/views/account/AccountSettingsView.coffee @@ -231,7 +231,7 @@ module.exports = class AccountSettingsView extends CocoView $('.nano').nanoScroller({scrollTo: @$el.find('.has-error')}) else noty - text: res.responseText + text: res.responseJSON?.message or res.responseText type: 'error' layout: 'topCenter' timeout: 5000 diff --git a/app/views/core/CreateAccountModal/BasicInfoView.coffee b/app/views/core/CreateAccountModal/BasicInfoView.coffee index 051b765a7..de5da382c 100644 --- a/app/views/core/CreateAccountModal/BasicInfoView.coffee +++ b/app/views/core/CreateAccountModal/BasicInfoView.coffee @@ -146,6 +146,11 @@ module.exports = class BasicInfoView extends CocoView }) forms.clearFormAlerts(@$el) + + if data.name and forms.validateEmail(data.name) + forms.setErrorToProperty(@$el, 'name', $.i18n.t('signup.name_is_email')) + return false + res = tv4.validateMultiple data, @formSchema() forms.applyErrorsToForm(@$('form'), res.errors) unless res.valid return res.valid diff --git a/server/models/User.coffee b/server/models/User.coffee index c26edbafa..0ed8aab85 100644 --- a/server/models/User.coffee +++ b/server/models/User.coffee @@ -361,6 +361,10 @@ UserSchema.pre('save', (next) -> @set('email', undefined) @set('emailLower', undefined) if name = @get('name') + filter = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}$/i # https://news.ycombinator.com/item?id=5763990 + if filter.test(name) + return next(new errors.UnprocessableEntity('Name may not be an email')) + @set('nameLower', name.toLowerCase()) else @set('name', undefined)