From 8ba1a082452e2dc53323ba0ab0587eeb847b5d80 Mon Sep 17 00:00:00 2001 From: Henry Oswald Date: Wed, 5 Mar 2014 11:57:57 +0000 Subject: [PATCH] hooked up password reset to use new email sending --- .../coffee/Features/Email/EmailBuilder.coffee | 2 +- .../coffee/Features/Email/EmailSender.coffee | 1 + .../coffee/controllers/UserController.coffee | 26 +++++++++---------- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/services/web/app/coffee/Features/Email/EmailBuilder.coffee b/services/web/app/coffee/Features/Email/EmailBuilder.coffee index 6f74a62af4..3ea111764e 100644 --- a/services/web/app/coffee/Features/Email/EmailBuilder.coffee +++ b/services/web/app/coffee/Features/Email/EmailBuilder.coffee @@ -46,7 +46,7 @@ templates.passwordReset = compiledTemplate: _.template '''

Password Reset

-Your password has been reset, the new password is

{{newPassword}}: +Your password has been reset, the new password is

{{newPassword}}

please login here and then change your password in your user settings diff --git a/services/web/app/coffee/Features/Email/EmailSender.coffee b/services/web/app/coffee/Features/Email/EmailSender.coffee index abaaf80a71..84f39b3699 100644 --- a/services/web/app/coffee/Features/Email/EmailSender.coffee +++ b/services/web/app/coffee/Features/Email/EmailSender.coffee @@ -4,6 +4,7 @@ Settings = require('settings-sharelatex') metrics = require("../../infrastructure/Metrics") ses = require('node-ses') + if Settings.email?.ses? and Settings.email.ses?.key? and Settings.email.ses?.key != "" and Settings.email.ses?.secret? and Settings.email.ses?.secret != "" client = ses.createClient({ key: Settings.email.ses.key, secret: Settings.email.ses.secret }); else diff --git a/services/web/app/coffee/controllers/UserController.coffee b/services/web/app/coffee/controllers/UserController.coffee index 2f2979fa59..13b0a7d2f6 100644 --- a/services/web/app/coffee/controllers/UserController.coffee +++ b/services/web/app/coffee/controllers/UserController.coffee @@ -2,7 +2,6 @@ User = require('../models/User').User sanitize = require('validator').sanitize fs = require('fs') _ = require('underscore') -emailer = require('../managers/EmailManager') logger = require('logger-sharelatex') Security = require('../managers/SecurityManager') Settings = require('settings-sharelatex') @@ -16,6 +15,7 @@ AuthenticationManager = require("../Features/Authentication/AuthenticationManage AuthenticationController = require("../Features/Authentication/AuthenticationController") SubscriptionLocator = require("../Features/Subscription/SubscriptionLocator") UserDeleter = require("../Features/User/UserDeleter") +EmailHandler = require("../Features/Email/EmailHandler") Url = require("url") module.exports = @@ -100,19 +100,17 @@ module.exports = if(user?) randomPassword = generateRandomString 12 AuthenticationManager.setUserPassword user._id, randomPassword, (error) -> - return next(error) if error? - emailOptions = - receiver : user.email - subject : "Password Reset - ShareLatex.com" - heading : "Password Reset" - message : " Your password has been reset, the new password is

#{randomPassword} -

please login click here - " - emailer.sendEmail emailOptions - metrics.inc "user.password-reset" - res.send message: - text:'An email with your new password has been sent to you' - type:'success' + emailOpts = + newPassword: randomPassword + to: user.email + EmailHandler.sendEmail "passwordReset", emailOpts, (err)-> + if err? + logger.err err:err, emailOpts:emailOpts, "problem sending password reset email" + return res.send 500 + metrics.inc "user.password-reset" + res.send message: + text:'An email with your new password has been sent to you' + type:'success' else res.send message: text:'This email address has not been registered with us'