more password reset things

This commit is contained in:
Cassie Tarakajian 2016-10-17 22:56:19 -04:00
parent 04f68e37f9
commit d055aa5af8
3 changed files with 27 additions and 2 deletions

View file

@ -16,12 +16,10 @@ class ResetPasswordView extends React.Component {
} }
render() { render() {
console.log(this.props.user);
const resetPasswordClass = classNames({ const resetPasswordClass = classNames({
'reset-password': true, 'reset-password': true,
'reset-password--submitted': this.props.user.resetPasswordInitiate 'reset-password--submitted': this.props.user.resetPasswordInitiate
}); });
console.log(resetPasswordClass);
return ( return (
<div className={resetPasswordClass} ref="resetPassword" tabIndex="0"> <div className={resetPasswordClass} ref="resetPassword" tabIndex="0">
<h1>Reset Your Password</h1> <h1>Reset Your Password</h1>

View file

@ -88,6 +88,7 @@
"mongoose": "^4.4.16", "mongoose": "^4.4.16",
"node-uuid": "^1.4.7", "node-uuid": "^1.4.7",
"nodemailer": "^2.6.4", "nodemailer": "^2.6.4",
"nodemailer-mailgun-transport": "^1.2.2",
"passport": "^0.3.2", "passport": "^0.3.2",
"passport-github": "^1.1.0", "passport-github": "^1.1.0",
"passport-local": "^1.0.0", "passport-local": "^1.0.0",

View file

@ -1,6 +1,8 @@
import User from '../models/user'; import User from '../models/user';
import crypto from 'crypto'; import crypto from 'crypto';
import async from 'async'; import async from 'async';
import nodemailer from 'nodemailer';
import mg from 'nodemailer-mailgun-transport';
export function createUser(req, res, next) { export function createUser(req, res, next) {
const user = new User({ const user = new User({
@ -95,12 +97,36 @@ export function resetPasswordInitiate(req, res) {
done(err, token, user); 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) => { ], (err) => {
if (err) { if (err) {
console.log(err); console.log(err);
return res.json({success: false}); 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.'}); return res.json({success: true, message: 'If the email is registered with the editor, an email has been sent.'});
}); });
} }