From cd77c3c022e4fb4cf0d1fce2614f4d93177be414 Mon Sep 17 00:00:00 2001 From: Nadav Date: Wed, 21 Apr 2021 20:28:14 +0300 Subject: [PATCH] Adding automatic confirmation emails after admitting users When an admin admits a participant using the admin page, the application sends an automatic email to the admittee in a similar manner to the verification emails. This is done by using the email-link-action template in `server/emails/email-link-action/html.pug Also, fixed some spelling mistakes in the comments. --- app/server/controllers/UserController.js | 13 +++++++++- app/server/services/email.js | 33 +++++++++++++++++++++--- 2 files changed, 42 insertions(+), 4 deletions(-) diff --git a/app/server/controllers/UserController.js b/app/server/controllers/UserController.js index 354f91f99..f27b367db 100644 --- a/app/server/controllers/UserController.js +++ b/app/server/controllers/UserController.js @@ -630,7 +630,7 @@ UserController.resetPassword = function(token, password, callback){ * [ADMIN ONLY] * * Admit a user. - * @param {String} userId User id of the admit + * @param {String} id User id of the admit * @param {String} user User doing the admitting * @param {Function} callback args(err, user) */ @@ -650,6 +650,17 @@ UserController.admitUser = function(id, user, callback){ new: true }, callback); + + //Find the user by the ID and send him an email + User.findOne({ + _id: id + }, + function(err, user){ + if (err || !user){ + return callback(err); + } + Mailer.sendConfirmationEmail(user.email); + }); }); }; diff --git a/app/server/services/email.js b/app/server/services/email.js index 9f93bfc90..46412dd78 100644 --- a/app/server/services/email.js +++ b/app/server/services/email.js @@ -97,7 +97,7 @@ controller.sendVerificationEmail = function(email, token, callback) { }; /** - * Eamil-verify takes a few template values: + * Email-verify takes a few template values: * { * verifyUrl: the url that the user must visit to verify their account * } @@ -116,6 +116,33 @@ controller.sendVerificationEmail = function(email, token, callback) { }; +controller.sendConfirmationEmail = function(email, callback) { + var options = { + to: email, + subject: "["+HACKATHON_NAME+"] - You've been admitted!" + }; + + var locals = { + title: 'Congrats! You\'ve been admitted to ' + HACKATHON_NAME + '!', + subtitle: '', + description: 'Please make sure you confirm your application by clicking the button below.', + actionUrl: ROOT_URL + '/confirmation', + actionName: 'Confirm Application' + }; + + sendOne('email-link-action', options, locals, function(err, info) { + if (err){ + console.log(err); + } + if (info){ + console.log(info.message); + } + if (callback){ + callback(err, info); + } + }); +}; + /** * Send a password recovery email. * @param {[type]} email [description] @@ -139,7 +166,7 @@ controller.sendPasswordResetEmail = function(email, token, callback) { }; /** - * Eamil-verify takes a few template values: + * Email-verify takes a few template values: * { * verifyUrl: the url that the user must visit to verify their account * } @@ -176,7 +203,7 @@ controller.sendPasswordChangedEmail = function(email, callback){ }; /** - * Eamil-verify takes a few template values: + * Email-verify takes a few template values: * { * verifyUrl: the url that the user must visit to verify their account * }