mirror of
https://github.com/wassname/talk.git
synced 2026-08-07 11:29:44 +08:00
throw instead of log errors. rename for clarity
This commit is contained in:
+4
-5
@@ -2,7 +2,6 @@ const mongoose = require('../mongoose');
|
||||
const uuid = require('uuid');
|
||||
const bcrypt = require('bcrypt');
|
||||
const jwt = require('jsonwebtoken');
|
||||
const debug = require('debug')('talk:user_model');
|
||||
|
||||
// SALT_ROUNDS is the number of rounds that the bcrypt algorithm will run
|
||||
// through during the salting process.
|
||||
@@ -15,7 +14,7 @@ const USER_ROLES = [
|
||||
];
|
||||
|
||||
if (!process.env.TALK_SESSION_SECRET) {
|
||||
debug('\n////////////////////////////////////////////////////////////\n' +
|
||||
throw new Error('\n////////////////////////////////////////////////////////////\n' +
|
||||
'/// TALK_SESSION_SECRET must be defined to encode ///\n' +
|
||||
'/// JSON Web Tokens and other auth functionality ///\n' +
|
||||
'////////////////////////////////////////////////////////////');
|
||||
@@ -413,7 +412,7 @@ UserService.findByIdArray = (ids) => {
|
||||
* Creates a JWT from a user email. Only works for local accounts.
|
||||
* @param {String} email of the local user
|
||||
*/
|
||||
UserService.createJWT = function (email) {
|
||||
UserService.createPasswordResetToken = function (email) {
|
||||
if (!email || typeof email !== 'string') {
|
||||
return Promise.reject('email is required when creating a JWT for resetting passord');
|
||||
}
|
||||
@@ -438,7 +437,7 @@ UserService.createJWT = function (email) {
|
||||
* verifies a jwt and returns the associated user
|
||||
* @param {String} token the JSON Web Token to verify
|
||||
*/
|
||||
UserService.verifyToken = function (token) {
|
||||
UserService.verifyPasswordResetToken = function (token) {
|
||||
return new Promise((resolve, reject) => {
|
||||
jwt.verify(token, process.env.TALK_SESSION_SECRET, (error, decoded) => {
|
||||
if (error) {
|
||||
@@ -454,7 +453,7 @@ UserService.verifyToken = function (token) {
|
||||
* and make an entry if it does not exist.
|
||||
* reject if entry already exists.
|
||||
*/
|
||||
return this.findOne({id: decoded.userId});
|
||||
return this.findById(decoded.userId);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ router.post('/:user_id/role', (req, res, next) => {
|
||||
router.post('/update-password', (req, res, next) => {
|
||||
const {token, password} = req.body;
|
||||
|
||||
User.verifyToken(token)
|
||||
User.verifyPasswordResetToken(token)
|
||||
.then(user => {
|
||||
return User.changePassword(user.id, password);
|
||||
})
|
||||
@@ -91,7 +91,7 @@ router.post('/request-password-reset', (req, res, next) => {
|
||||
}
|
||||
|
||||
User
|
||||
.createJWT(email)
|
||||
.createPasswordResetToken(email)
|
||||
.then(token => {
|
||||
const options = {
|
||||
subject: 'Password Reset Requested - Talk',
|
||||
|
||||
+1
-2
@@ -1,8 +1,7 @@
|
||||
const nodemailer = require('nodemailer');
|
||||
const debug = require('debug')('talk:mail');
|
||||
|
||||
if (!process.env.TALK_SMTP_CONNECTION_URL) {
|
||||
debug('\n///////////////////////////////////////////////////////////////\n' +
|
||||
throw new Error('\n///////////////////////////////////////////////////////////////\n' +
|
||||
'/// TALK_SMTP_CONNECTION_URL should be defined if you would ///\n' +
|
||||
'/// like to send password reset emails from Talk ///\n' +
|
||||
'///////////////////////////////////////////////////////////////');
|
||||
|
||||
Reference in New Issue
Block a user