mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-03 17:33:31 -04:00
Merge branch 'master' of https://github.com/codecombat/codecombat
This commit is contained in:
commit
fd758f2d4b
1 changed files with 23 additions and 20 deletions
|
@ -2,34 +2,30 @@ mail = require '../commons/mail'
|
||||||
map = _.invert mail.MAILCHIMP_GROUP_MAP
|
map = _.invert mail.MAILCHIMP_GROUP_MAP
|
||||||
User = require '../users/User.coffee'
|
User = require '../users/User.coffee'
|
||||||
errors = require '../commons/errors'
|
errors = require '../commons/errors'
|
||||||
request = require 'request'
|
#request = require 'request'
|
||||||
config = require '../../server_config'
|
config = require '../../server_config'
|
||||||
|
|
||||||
badLog = (text) ->
|
#badLog = (text) ->
|
||||||
console.log text
|
# console.log text
|
||||||
request.post 'http://requestb.in/1brdpaz1', { form: {log: text} }
|
# request.post 'http://requestb.in/1brdpaz1', { form: {log: text} }
|
||||||
|
|
||||||
module.exports.setupRoutes = (app) ->
|
module.exports.setupRoutes = (app) ->
|
||||||
app.all config.mail.mailchimpWebhook, (req, res) ->
|
app.all config.mail.mailchimpWebhook, (req, res) ->
|
||||||
post = req.body
|
post = req.body
|
||||||
badLog("Got post data: #{JSON.stringify(post, null, '\t')}")
|
# badLog("Got post data: #{JSON.stringify(post, null, '\t')}")
|
||||||
|
|
||||||
unless post.type in ['unsubscribe', 'profile']
|
unless post.type in ['unsubscribe', 'profile']
|
||||||
badLog("Bad post type: #{post.type}")
|
res.send 'Bad post type'
|
||||||
return errors.badInput(res, 'Bad post type')
|
return res.end()
|
||||||
|
|
||||||
unless post.data.email
|
unless post.data.email
|
||||||
badLog("Ignoring because no email: #{JSON.stringify(req.body, null, '\t')}")
|
res.send 'No email provided'
|
||||||
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()
|
return res.end()
|
||||||
|
|
||||||
User.findOne {'mailChimp.euid':post.data.id}, (err, user) ->
|
query = {'mailChimp.leid':post.data.web_id}
|
||||||
|
User.findOne query, (err, user) ->
|
||||||
return errors.serverError(res) if err
|
return errors.serverError(res) if err
|
||||||
if not user
|
if not user
|
||||||
badLog("could not find user for...: #{{'mailChimp.euid':post.data.id}}")
|
|
||||||
return errors.notFound(res)
|
return errors.notFound(res)
|
||||||
|
|
||||||
handleProfileUpdate(user, post) if post.type is 'profile'
|
handleProfileUpdate(user, post) if post.type is 'profile'
|
||||||
|
@ -44,15 +40,22 @@ module.exports.setupRoutes = (app) ->
|
||||||
handleProfileUpdate = (user, post) ->
|
handleProfileUpdate = (user, post) ->
|
||||||
groups = post.data.merges.INTERESTS.split(', ')
|
groups = post.data.merges.INTERESTS.split(', ')
|
||||||
groups = (map[g] for g in groups when map[g])
|
groups = (map[g] for g in groups when map[g])
|
||||||
|
otherSubscriptions = (g for g in user.get('emailSubscriptions') when not mail.MAILCHIMP_GROUP_MAP[g])
|
||||||
|
groups = groups.concat otherSubscriptions
|
||||||
user.set 'emailSubscriptions', groups
|
user.set 'emailSubscriptions', groups
|
||||||
|
|
||||||
mailChimpInfo = user.get 'mailChimp'
|
fname = post.data.merges.FNAME
|
||||||
mailChimpInfo.email = post.data.merges.EMAIL
|
user.set('firstName', fname) if fname
|
||||||
user.set 'mailChimp', mailChimpInfo
|
|
||||||
|
|
||||||
badLog("Updating user object to: #{JSON.stringify(user.toObject(), null, '\t')}")
|
lname = post.data.merges.LNAME
|
||||||
|
user.set('lastName', lname) if lname
|
||||||
|
|
||||||
|
user.set 'mailChimp.email', post.data.email
|
||||||
|
user.set 'mailChimp.euid', post.data.id
|
||||||
|
|
||||||
|
# badLog("Updating user object to: #{JSON.stringify(user.toObject(), null, '\t')}")
|
||||||
|
|
||||||
handleUnsubscribe = (user) ->
|
handleUnsubscribe = (user) ->
|
||||||
user.set 'emailSubscriptions', []
|
user.set 'emailSubscriptions', []
|
||||||
|
|
||||||
badLog("Unsubscribing user object to: #{JSON.stringify(user.toObject(), null, '\t')}")
|
# badLog("Unsubscribing user object to: #{JSON.stringify(user.toObject(), null, '\t')}")
|
Loading…
Add table
Add a link
Reference in a new issue