mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-26 22:13:32 -04:00
Set up sendwithus.
Created a 'notification' email subscription.
This commit is contained in:
parent
c5b9b103c5
commit
3caf16ae0c
6 changed files with 30 additions and 5 deletions
|
@ -82,7 +82,13 @@ block content
|
|||
.controls
|
||||
input#email_announcement(name="email_announcement", type="checkbox", checked=subs.announcement)
|
||||
span.help-inline(data-i18n="account_settings.email_announcements_description") Get emails on the latest news and developments at CodeCombat.
|
||||
|
||||
|
||||
.form-horizontal
|
||||
.control-group
|
||||
label.control-label(for="email_notification", data-i18n="account_settings.email_notifications") Notifications
|
||||
.controls
|
||||
input#email_notification(name="email_notification", type="checkbox", checked=subs.notification)
|
||||
span.help-inline(data-i18n="account_settings.email_notifications_description") Get periodic notifications for your account.
|
||||
hr
|
||||
|
||||
.form-horizontal
|
||||
|
|
|
@ -58,7 +58,8 @@
|
|||
"mailchimp-api": "",
|
||||
"express-useragent": "~0.0.9",
|
||||
"gridfs-stream": "",
|
||||
"stream-buffers": ""
|
||||
"stream-buffers": "",
|
||||
"sendwithus": ""
|
||||
},
|
||||
"devDependencies": {
|
||||
"jade": "0.33.x",
|
||||
|
|
|
@ -3,6 +3,8 @@ jsonschema = require('../schemas/user')
|
|||
crypto = require('crypto')
|
||||
{salt, isProduction} = require('../../server_config')
|
||||
|
||||
sendwithus = require '../sendwithus'
|
||||
|
||||
UserSchema = new mongoose.Schema({
|
||||
dateCreated:
|
||||
type: Date
|
||||
|
@ -32,7 +34,7 @@ UserSchema.statics.updateMailChimp = (doc, callback) ->
|
|||
existingProps = doc.get('mailChimp')
|
||||
emailChanged = (not existingProps) or existingProps?.email isnt doc.get('email')
|
||||
emailSubs = doc.get('emailSubscriptions')
|
||||
newGroups = (groupingMap[name] for name in emailSubs)
|
||||
newGroups = (groupingMap[name] for name in emailSubs when groupingMap[name]?)
|
||||
if (not existingProps) and newGroups.length is 0
|
||||
return callback?() # don't add totally unsubscribed people to the list
|
||||
subsChanged = doc.currentSubscriptions isnt JSON.stringify(emailSubs)
|
||||
|
@ -65,7 +67,14 @@ UserSchema.pre('save', (next) ->
|
|||
if @get('password')
|
||||
@set('passwordHash', User.hashPassword(pwd))
|
||||
@set('password', undefined)
|
||||
@set('anonymous', false) if @get('email')
|
||||
if @get('email') and @get('anonymous')
|
||||
@set('anonymous', false)
|
||||
data =
|
||||
email_id: sendwithus.templates.welcome_email
|
||||
recipient:
|
||||
address: @get 'email'
|
||||
sendwithus.api.send data, (err, result) ->
|
||||
console.log 'error', err, 'result', result
|
||||
next()
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
c = require './common'
|
||||
emailSubscriptions = ['announcement', 'tester', 'level_creator', 'developer', 'article_editor', 'translator', 'support']
|
||||
emailSubscriptions = ['announcement', 'tester', 'level_creator', 'developer', 'article_editor', 'translator', 'support', 'notification']
|
||||
|
||||
UserSchema = c.object {},
|
||||
name: c.shortString({title: 'Display Name', default:''})
|
||||
|
|
8
server/sendwithus.coffee
Normal file
8
server/sendwithus.coffee
Normal file
|
@ -0,0 +1,8 @@
|
|||
config = require '../server_config'
|
||||
sendwithusAPI = require 'sendwithus'
|
||||
swuAPIKey = config.mail.sendwithusAPIKey
|
||||
|
||||
options = { DEBUG: not config.isProduction }
|
||||
module.exports.api = new sendwithusAPI swuAPIKey, options
|
||||
module.exports.templates =
|
||||
welcome_email: 'utnGaBHuSU4Hmsi7qrAypU'
|
|
@ -27,6 +27,7 @@ config.mail.service = process.env.COCO_MAIL_SERVICE_NAME || "Zoho";
|
|||
config.mail.username = process.env.COCO_MAIL_SERVICE_USERNAME || "";
|
||||
config.mail.password = process.env.COCO_MAIL_SERVICE_PASSWORD || "";
|
||||
config.mail.mailchimpAPIKey = process.env.COCO_MAILCHIMP_API_KEY || '';
|
||||
config.mail.sendwithusAPIKey = process.env.COCO_SENDWITHUS_API_KEY || '';
|
||||
|
||||
config.salt = process.env.COCO_SALT || 'pepper';
|
||||
config.cookie_secret = process.env.COCO_COOKIE_SECRET || 'chips ahoy';
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue