mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-24 21:13:35 -04:00
Added unsubscribe view.
This commit is contained in:
parent
104ea27dc0
commit
8b0a0c4e51
4 changed files with 76 additions and 0 deletions
app
server
8
app/styles/account/unsubscribe.sass
Normal file
8
app/styles/account/unsubscribe.sass
Normal file
|
@ -0,0 +1,8 @@
|
|||
#unsubscribe-view
|
||||
text-align: center
|
||||
|
||||
p
|
||||
margin: 20px 0
|
||||
|
||||
.bar
|
||||
width: 100%
|
17
app/templates/account/unsubscribe.jade
Normal file
17
app/templates/account/unsubscribe.jade
Normal file
|
@ -0,0 +1,17 @@
|
|||
extends /templates/base
|
||||
|
||||
block content
|
||||
|
||||
p
|
||||
span(data-i18n="account.unsubscribe") Unsubscribing for
|
||||
span
|
||||
strong= email
|
||||
|
||||
button.btn.btn-warning#unsubscribe-button(data-i18n="account.unsubscribe_button") Do it
|
||||
|
||||
.progress.progress-striped.active.hide
|
||||
.bar
|
||||
|
||||
p.hide#fail-alert(data-i18n="account.unsubscribe_failed").alert.alert-danger Failed
|
||||
|
||||
p.hide#success-alert(data-i18n="account.unsubscribe_success").alert.alert-success Success
|
35
app/views/account/unsubscribe_view.coffee
Normal file
35
app/views/account/unsubscribe_view.coffee
Normal file
|
@ -0,0 +1,35 @@
|
|||
RootView = require 'views/kinds/RootView'
|
||||
template = require 'templates/account/unsubscribe'
|
||||
{me} = require 'lib/auth'
|
||||
|
||||
module.exports = class UnsubscribeView extends RootView
|
||||
id: "unsubscribe-view"
|
||||
template: template
|
||||
|
||||
events:
|
||||
'click #unsubscribe-button': 'onUnsubscribeButtonClicked'
|
||||
|
||||
getRenderData: ->
|
||||
context = super()
|
||||
context.email = @getQueryVariable 'email'
|
||||
context
|
||||
|
||||
onUnsubscribeButtonClicked: ->
|
||||
@$el.find('#unsubscribe-button').addClass 'hide'
|
||||
@$el.find('.progress').removeClass 'hide'
|
||||
@$el.find('.alert').addClass 'hide'
|
||||
|
||||
email = @getQueryVariable 'email'
|
||||
url = "/auth/unsubscribe?email=#{encodeURIComponent(email)}"
|
||||
|
||||
success = =>
|
||||
@$el.find('.progress').addClass 'hide'
|
||||
@$el.find('#success-alert').removeClass 'hide'
|
||||
me.fetch()
|
||||
|
||||
error = =>
|
||||
@$el.find('.progress').addClass 'hide'
|
||||
@$el.find('#fail-alert').removeClass 'hide'
|
||||
@$el.find('#unsubscribe-button').removeClass 'hide'
|
||||
|
||||
$.ajax { url: url, success: success, error: error }
|
|
@ -79,6 +79,22 @@ module.exports.setupRoutes = (app) ->
|
|||
return res.end()
|
||||
)
|
||||
)
|
||||
|
||||
app.get '/auth/unsubscribe', (req, res) ->
|
||||
email = req.query.email
|
||||
unless req.query.email
|
||||
return errors.badInput res, 'No email provided to unsubscribe.'
|
||||
|
||||
User.findOne({emailLower:req.query.email.toLowerCase()}).exec (err, user) ->
|
||||
if not user
|
||||
return errors.notFound res, "No user found with email '#{req.query.email}'"
|
||||
|
||||
user.set('emailSubscriptions', [])
|
||||
user.save (err) =>
|
||||
return errors.serverError res, 'Database failure.' if err
|
||||
|
||||
res.send "Unsubscribed #{req.query.email} from all CodeCombat emails. Sorry to see you go! <p><a href='/account/settings'>Account settings</a></p>"
|
||||
res.end()
|
||||
|
||||
createMailOptions = (receiver, password) ->
|
||||
# TODO: use email templates here
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue