mirror of
https://github.com/wassname/talk.git
synced 2026-08-11 11:27:10 +08:00
better error reporting. log when env variable is unset
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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: `<p>We received a request to reset your password. If you did not request this change, you can ignore this email.
|
||||
If you did, <a href="http://localhost:3000/admin/password-reset/${token}">please click here to reset password</a>.</p>
|
||||
${process.env.NODE_ENV === 'production' ? '' : `<h1>${token}</h1>`}`
|
||||
${process.env.NODE_ENV === 'production' ? '' : `<p style="color: red">${token}</p>`}`
|
||||
};
|
||||
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});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user