Fixes various bugs in mandrill.js

Adds more detailed logging to mandrill.js
Send confirmation emails on learner account signup.
This commit is contained in:
Mike Larsson 2013-05-23 15:44:57 -04:00
Родитель 6fa9172619
Коммит 870a230081
2 изменённых файлов: 23 добавлений и 3 удалений

Просмотреть файл

@ -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');
@ -178,6 +180,7 @@ function processChildLearnerSignup (req, res, next) {
}).complete(function(err) {
if (err) return fail(err);
email.send('<13 learner signup', {}, signup.parent_email);
delete req.session.signup;
req.flash('modal', {
title: 'Welcome to the Chicago Summer of Learning',
@ -239,6 +242,7 @@ function processStandardLearnerSignup (req, res, next) {
return fail(err);
}
email.send('learner signup', {}, signup.email);
delete req.session.signup;
redirectUser(req, res, user);
});

Просмотреть файл

@ -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 = {
@ -66,7 +67,7 @@ module.exports = {
var payload = {
key: KEY,
template_name: template,
template_name: TEMPLATES[template],
template_content: [],
message: {
to: recipients,
@ -89,6 +90,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);
});
}