From d055aa5af863c210a80e570eaaa68811e18962b5 Mon Sep 17 00:00:00 2001 From: Cassie Tarakajian Date: Mon, 17 Oct 2016 22:56:19 -0400 Subject: [PATCH] more password reset things --- .../IDE/components/ResetPasswordView.js | 2 -- package.json | 1 + server/controllers/user.controller.js | 26 +++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/client/modules/IDE/components/ResetPasswordView.js b/client/modules/IDE/components/ResetPasswordView.js index e46ad887..628531f0 100644 --- a/client/modules/IDE/components/ResetPasswordView.js +++ b/client/modules/IDE/components/ResetPasswordView.js @@ -16,12 +16,10 @@ class ResetPasswordView extends React.Component { } render() { - console.log(this.props.user); const resetPasswordClass = classNames({ 'reset-password': true, 'reset-password--submitted': this.props.user.resetPasswordInitiate }); - console.log(resetPasswordClass); return (

Reset Your Password

diff --git a/package.json b/package.json index 225a34f8..9085b058 100644 --- a/package.json +++ b/package.json @@ -88,6 +88,7 @@ "mongoose": "^4.4.16", "node-uuid": "^1.4.7", "nodemailer": "^2.6.4", + "nodemailer-mailgun-transport": "^1.2.2", "passport": "^0.3.2", "passport-github": "^1.1.0", "passport-local": "^1.0.0", diff --git a/server/controllers/user.controller.js b/server/controllers/user.controller.js index d453d37c..e04220f6 100644 --- a/server/controllers/user.controller.js +++ b/server/controllers/user.controller.js @@ -1,6 +1,8 @@ import User from '../models/user'; import crypto from 'crypto'; import async from 'async'; +import nodemailer from 'nodemailer'; +import mg from 'nodemailer-mailgun-transport'; export function createUser(req, res, next) { const user = new User({ @@ -95,12 +97,36 @@ export function resetPasswordInitiate(req, res) { done(err, token, user); }); }); + }, + (token, user, done) => { + const auth = { + auth: { + api_key: process.env.MAILGUN_KEY, + domain: process.env.MAILGUN_DOMAIN + } + }; + + const transporter = nodemailer.createTransport(mg(auth)); + const message = { + to: user.email, + from: 'passwordreset@mg.p5js.org', + subject: 'p5.js Web Editor Password Reset', + text: `You are receiving this email because you (or someone else) have requested + the reset of the password for your account. \n\n Please click on the following link, + or paste this into your browser to complete the process: \n\n + http://${req.headers.host}/reset-password/${token}\n\n + If you did not request this, please ignore this email and your password will remain unchanged.\n` + }; + transporter.sendMail(message, (error, info) => { + done(error); + }); } ], (err) => { if (err) { console.log(err); return res.json({success: false}); } + //send email here return res.json({success: true, message: 'If the email is registered with the editor, an email has been sent.'}); }); }