mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-03-25 12:20:32 -04:00
Merge branch 'production'
This commit is contained in:
commit
6d76f7b346
1 changed files with 27 additions and 3 deletions
|
@ -5,16 +5,36 @@ errors = require '../commons/errors'
|
|||
request = require 'request'
|
||||
config = require '../../server_config'
|
||||
|
||||
badLog = (text) ->
|
||||
console.log text
|
||||
request.post 'http://requestb.in/1brdpaz1', { form: {log: text} }
|
||||
|
||||
module.exports.setupRoutes = (app) ->
|
||||
app.all config.mail.mailchimpWebhook, (req, res) ->
|
||||
post = req.body
|
||||
return res.end() unless post.type in ['unsubscribe', 'profile']
|
||||
return res.end() unless post.data.email
|
||||
badLog("Got post data: #{JSON.stringify(post, null, '\t')}")
|
||||
|
||||
unless post.type in ['unsubscribe', 'profile']
|
||||
badLog("Bad post type: #{post.type}")
|
||||
return errors.badInput(res, 'Bad post type')
|
||||
|
||||
unless post.data.email
|
||||
badLog("Ignoring because no email: #{JSON.stringify(req.body, null, '\t')}")
|
||||
return errors.badInput(res, 'No email provided')
|
||||
|
||||
unless post.data.email is 'sderickson@gmail.com'
|
||||
badLog("Ignoring because this is a test: #{JSON.stringify(req.body, null, '\t')}")
|
||||
return res.end()
|
||||
|
||||
User.findOne {'mailChimp.euid':post.data.id}, (err, user) ->
|
||||
return errors.serverError(res) if err
|
||||
return errors.notFound(res) if not user
|
||||
if not user
|
||||
badLog("could not find user for...: #{{'mailChimp.euid':post.data.id}}")
|
||||
return errors.notFound(res) if err
|
||||
|
||||
handleProfileUpdate(user, post) if post.type is 'profile'
|
||||
handleUnsubscribe(user) if post.type is 'unsubscribe'
|
||||
|
||||
user.updatedMailChimp = true # so as not to echo back to mailchimp
|
||||
user.save (err) ->
|
||||
return errors.serverError(res) if err
|
||||
|
@ -29,6 +49,10 @@ handleProfileUpdate = (user, post) ->
|
|||
mailChimpInfo = user.get 'mailChimp'
|
||||
mailChimpInfo.email = post.data.email
|
||||
user.set 'mailChimp', mailChimpInfo
|
||||
|
||||
badLog("Updating user object to: #{JSON.stringify(user.toObject(), null, '\t')}")
|
||||
|
||||
handleUnsubscribe = (user) ->
|
||||
user.set 'emailSubscriptions', []
|
||||
|
||||
badLog("Unsubscribing user object to: #{JSON.stringify(user.toObject(), null, '\t')}")
|
Loading…
Add table
Reference in a new issue