mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 09:35:39 -05:00
Prevent users from signing up with or changing to an email-like username
This commit is contained in:
parent
782aacf35e
commit
053ce34faf
4 changed files with 11 additions and 1 deletions
|
@ -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"
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue