зеркало из https://github.com/mozilla/CSOL-site.git
Merge remote-tracking branch 'stenington/mandrill-email'
This commit is contained in:
Коммит
d071d48084
|
@ -2,6 +2,8 @@ var bcrypt = require('bcrypt');
|
|||
var passwords = require('../lib/passwords');
|
||||
var usernames = require('../lib/usernames');
|
||||
var db = require('../db');
|
||||
var email = require('../mandrill');
|
||||
var logger = require('../logger');
|
||||
var learners = db.model('Learner');
|
||||
var guardians = db.model('Guardian');
|
||||
var signupTokens = db.model('SignupToken');
|
||||
|
@ -175,8 +177,6 @@ function processChildLearnerSignup (req, res, next) {
|
|||
}).complete(function(err, token) {
|
||||
if (err || !token) return fail(err);
|
||||
|
||||
// TODO - send an email
|
||||
|
||||
token.setLearner(user); // Assuming this worked
|
||||
|
||||
bcrypt.hash(signup.password, BCRYPT_SEED_ROUNDS, function(err, hash) {
|
||||
|
@ -189,6 +189,11 @@ function processChildLearnerSignup (req, res, next) {
|
|||
}).complete(function(err) {
|
||||
if (err) return fail(err);
|
||||
|
||||
var confirmationUrl = req.protocol + '://' + req.get('Host')
|
||||
+ '/signup/' + token.token;
|
||||
email.send('<13 learner signup', {
|
||||
confirmationUrl: confirmationUrl
|
||||
}, signup.parent_email);
|
||||
delete req.session.signup;
|
||||
req.flash('modal', {
|
||||
title: 'Welcome to the Chicago Summer of Learning',
|
||||
|
@ -250,6 +255,7 @@ function processStandardLearnerSignup (req, res, next) {
|
|||
return fail(err);
|
||||
}
|
||||
|
||||
email.send('learner signup', {}, signup.email);
|
||||
delete req.session.signup;
|
||||
redirectUser(req, res, user);
|
||||
});
|
||||
|
|
25
mandrill.js
25
mandrill.js
|
@ -7,7 +7,7 @@ const FAKE_EMAIL = ('DEBUG' in process.env)
|
|||
|
||||
var request = require('request');
|
||||
if (FAKE_EMAIL) {
|
||||
request = function(opts, cb) {
|
||||
request.post = function(opts, cb) {
|
||||
logger.log('debug', 'FAKE EMAIL: request.post with opts', opts);
|
||||
cb('EMAIL DISABLED');
|
||||
};
|
||||
|
@ -18,7 +18,8 @@ const ENDPOINT = process.env['CSOL_MANDRILL_URL'] ||
|
|||
const KEY = process.env['CSOL_MANDRILL_KEY'];
|
||||
|
||||
const TEMPLATES = {
|
||||
test: 'test'
|
||||
'<13 learner signup': 'csol-13-signup',
|
||||
'learner signup': 'csol-signup'
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
@ -26,7 +27,8 @@ module.exports = {
|
|||
/*
|
||||
send(template, context, recipient, callback)
|
||||
|
||||
template - internal template name, mapped to mandrill names above
|
||||
template - internal template name, mapped to mandrill names above, or
|
||||
mandrill template name
|
||||
context - merge variables (optional)
|
||||
{ foo: 'hi' } replaces *|foo|* or *|FOO|*
|
||||
in the template with "hi"
|
||||
|
@ -66,7 +68,7 @@ module.exports = {
|
|||
|
||||
var payload = {
|
||||
key: KEY,
|
||||
template_name: template,
|
||||
template_name: TEMPLATES[template] || template,
|
||||
template_content: [],
|
||||
message: {
|
||||
to: recipients,
|
||||
|
@ -89,6 +91,21 @@ module.exports = {
|
|||
if (response.statusCode !== 200)
|
||||
return callback(body);
|
||||
|
||||
var unsent = [];
|
||||
_.map(body, function(result) {
|
||||
var level = 'info';
|
||||
if (['sent', 'queued'].indexOf(result.status) === -1) {
|
||||
level = 'error';
|
||||
unsent.push(result);
|
||||
}
|
||||
logger.log(level, 'Learner signup email %s for %s', result.status, result.email);
|
||||
});
|
||||
if (unsent.length)
|
||||
return callback({
|
||||
message: 'Some addresses not sent or queued',
|
||||
results: unsent
|
||||
});
|
||||
|
||||
return callback(null, body);
|
||||
});
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче