mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-24 19:59:53 -04:00
1. email validation when subscribing other users
This commit is contained in:
parent
b9f0aa1622
commit
e0be8e94ea
3 changed files with 33 additions and 1 deletions
|
@ -1,4 +1,11 @@
|
||||||
#subscription-view
|
#subscription-view
|
||||||
|
|
||||||
|
.invalid-email-message
|
||||||
|
color: red
|
||||||
|
font-size: 12px
|
||||||
|
|
||||||
|
.recipient-emails.invalid
|
||||||
|
border: 1px solid red
|
||||||
|
|
||||||
.logged-out-blurb
|
.logged-out-blurb
|
||||||
font-size: 18px
|
font-size: 18px
|
||||||
|
|
|
@ -150,6 +150,8 @@ block content
|
||||||
if recipientSubs.state === 'subscribing'
|
if recipientSubs.state === 'subscribing'
|
||||||
.alert.alert-info(data-i18n="subscribe.subscribing")
|
.alert.alert-info(data-i18n="subscribe.subscribing")
|
||||||
else
|
else
|
||||||
|
if emailValidator.state === 'invalid'
|
||||||
|
div.invalid-email-message(aria-hidden="true") please make sure all entries are valid emails
|
||||||
textarea.recipient-emails(rows=3, data-i18n="[placeholder]subscribe.recipient_emails_placeholder")
|
textarea.recipient-emails(rows=3, data-i18n="[placeholder]subscribe.recipient_emails_placeholder")
|
||||||
div
|
div
|
||||||
button.recipients-subscribe-button.btn.btn-lg.btn-success(data-i18n="subscribe.subscribe_users")
|
button.recipients-subscribe-button.btn.btn-lg.btn-success(data-i18n="subscribe.subscribe_users")
|
||||||
|
|
|
@ -49,6 +49,7 @@ module.exports = class SubscriptionView extends RootView
|
||||||
prepaidCode = utils.getQueryVariable '_ppc'
|
prepaidCode = utils.getQueryVariable '_ppc'
|
||||||
@personalSub = new PersonalSub(@supermodel, prepaidCode)
|
@personalSub = new PersonalSub(@supermodel, prepaidCode)
|
||||||
@recipientSubs = new RecipientSubs(@supermodel)
|
@recipientSubs = new RecipientSubs(@supermodel)
|
||||||
|
@emailValidator = new EmailValidator(@superModel)
|
||||||
@personalSub.update => @render?()
|
@personalSub.update => @render?()
|
||||||
@recipientSubs.update => @render?()
|
@recipientSubs.update => @render?()
|
||||||
|
|
||||||
|
@ -56,6 +57,7 @@ module.exports = class SubscriptionView extends RootView
|
||||||
c = super()
|
c = super()
|
||||||
c.personalSub = @personalSub
|
c.personalSub = @personalSub
|
||||||
c.recipientSubs = @recipientSubs
|
c.recipientSubs = @recipientSubs
|
||||||
|
c.emailValidator = @emailValidator
|
||||||
c
|
c
|
||||||
|
|
||||||
# Personal Subscriptions
|
# Personal Subscriptions
|
||||||
|
@ -88,7 +90,8 @@ module.exports = class SubscriptionView extends RootView
|
||||||
|
|
||||||
onClickRecipientsSubscribe: (e) ->
|
onClickRecipientsSubscribe: (e) ->
|
||||||
emails = @$el.find('.recipient-emails').val().split('\n')
|
emails = @$el.find('.recipient-emails').val().split('\n')
|
||||||
@recipientSubs.startSubscribe(emails)
|
valid = @emailValidator.validateEmails(emails, =>@render?())
|
||||||
|
@recipientSubs.startSubscribe(emails) if valid
|
||||||
|
|
||||||
onClickRecipientUnsubscribe: (e) ->
|
onClickRecipientUnsubscribe: (e) ->
|
||||||
$(e.target).addClass('hide')
|
$(e.target).addClass('hide')
|
||||||
|
@ -102,6 +105,26 @@ module.exports = class SubscriptionView extends RootView
|
||||||
@recipientSubs.finishSubscribe(e.token.id, => @render?())
|
@recipientSubs.finishSubscribe(e.token.id, => @render?())
|
||||||
|
|
||||||
# Helper classes for managing subscription actions and updating UI state
|
# Helper classes for managing subscription actions and updating UI state
|
||||||
|
|
||||||
|
|
||||||
|
class EmailValidator
|
||||||
|
|
||||||
|
validateEmails: (emails, render) ->
|
||||||
|
emailRegex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i
|
||||||
|
@validEmails = (emailRegex.test(email.trim().toLowerCase()) for email in emails)
|
||||||
|
return @emailsInvalid(render) if _.contains(@validEmails, false)
|
||||||
|
return @emailsValid(render)
|
||||||
|
|
||||||
|
emailsInvalid: (render) ->
|
||||||
|
@state = "invalid"
|
||||||
|
render()
|
||||||
|
return false
|
||||||
|
|
||||||
|
emailsValid: (render) ->
|
||||||
|
@state = "valid"
|
||||||
|
render()
|
||||||
|
return true
|
||||||
|
|
||||||
|
|
||||||
class PersonalSub
|
class PersonalSub
|
||||||
constructor: (@supermodel, @prepaidCode) ->
|
constructor: (@supermodel, @prepaidCode) ->
|
||||||
|
|
Loading…
Add table
Reference in a new issue