diff --git a/models/user.js b/models/user.js index c3c81010a..7d083f70d 100644 --- a/models/user.js +++ b/models/user.js @@ -2,9 +2,17 @@ const mongoose = require('../mongoose'); const uuid = require('uuid'); const bcrypt = require('bcrypt'); const jwt = require('jsonwebtoken'); +const debug = require('debug')('talk:user_model'); const SALT_ROUNDS = 10; +if (!process.env.TALK_SESSION_SECRET) { + debug('\n////////////////////////////////////////////////////////////\n' + + '/// TALK_SESSION_SECRET must be defined to encode ///\n' + + '/// JSON Web Tokens and other auth functionality ///\n' + + '////////////////////////////////////////////////////////////'); +} + const UserSchema = new mongoose.Schema({ id: { type: String, diff --git a/routes/api/user/index.js b/routes/api/user/index.js index 808ad6940..c9b497659 100644 --- a/routes/api/user/index.js +++ b/routes/api/user/index.js @@ -99,8 +99,6 @@ router.post('/update-password', (req, res, next) => { router.post('/request-password-reset', (req, res, next) => { const {email} = req.body; - console.log('/request-password-reset', req.body); - if (!email) { return next(); } @@ -109,12 +107,12 @@ router.post('/request-password-reset', (req, res, next) => { .createJWT(email) .then(token => { const options = { - subject: 'password reset requested', + subject: 'Password Reset Requested - Talk', from: 'coralcore@mozillafoundation.org', - to: 'riley.davis@gmail.com', + to: email, html: `
We received a request to reset your password. If you did not request this change, you can ignore this email. If you did, please click here to reset password.
- ${process.env.NODE_ENV === 'production' ? '' : `${token}
`}` }; return mailer.sendSimple(options); }) @@ -122,7 +120,9 @@ router.post('/request-password-reset', (req, res, next) => { res.json({success: true}); }) .catch(error => { - res.status(500).json({error}); + const errorMsg = typeof error === 'string' ? error : error.message; + + res.status(500).json({error: errorMsg}); }); }); diff --git a/services/mailer.js b/services/mailer.js index eb900d782..89115d619 100644 --- a/services/mailer.js +++ b/services/mailer.js @@ -1,11 +1,19 @@ const nodemailer = require('nodemailer'); const sgTransport = require('nodemailer-sendgrid-transport'); +const debug = require('debug')('talk:mail'); const options = { auth: { api_key: process.env.TALK_SENDGRID_APIKEY } }; +if (!process.env.TALK_SENDGRID_APIKEY) { + debug('\n///////////////////////////////////////////////////////////////\n' + + '/// TALK_SENDGRID_APIKEY should be defined if you would ///\n' + + '/// like to send password reset emails from Talk ///\n' + + '///////////////////////////////////////////////////////////////'); +} + const transporter = nodemailer.createTransport(sgTransport(options)); const mailer = {