merge master

This commit is contained in:
riley
2017-05-16 16:33:41 -06:00
219 changed files with 3845 additions and 1847 deletions
+11 -17
View File
@@ -1,12 +1,14 @@
const assert = require('assert');
const uuid = require('uuid');
const bcrypt = require('bcrypt');
const url = require('url');
const jwt = require('jsonwebtoken');
const Wordlist = require('./wordlist');
const errors = require('../errors');
const uuid = require('uuid');
const {
JWT_SECRET,
ROOT_URL
} = require('../config');
const redis = require('./redis');
const redisClient = redis.createClient();
@@ -22,14 +24,6 @@ const SettingsService = require('./settings');
const ActionsService = require('./actions');
const MailerService = require('./mailer');
// In the event that the TALK_SESSION_SECRET is missing but we are testing, then
// set the process.env.TALK_SESSION_SECRET.
if (process.env.NODE_ENV === 'test' && !process.env.TALK_SESSION_SECRET) {
process.env.TALK_SESSION_SECRET = 'keyboard cat';
} else if (!process.env.TALK_SESSION_SECRET) {
throw new Error('TALK_SESSION_SECRET must be defined to encode JSON Web Tokens and other auth functionality');
}
const EMAIL_CONFIRM_JWT_SUBJECT = 'email_confirm';
const PASSWORD_RESET_JWT_SUBJECT = 'password_reset';
@@ -561,7 +555,7 @@ module.exports = class UsersService {
version: user.__v
};
return jwt.sign(payload, process.env.TALK_SESSION_SECRET, {
return jwt.sign(payload, JWT_SECRET, {
algorithm: 'HS256',
expiresIn: '1d',
subject: PASSWORD_RESET_JWT_SUBJECT
@@ -580,7 +574,7 @@ module.exports = class UsersService {
// Set the allowed algorithms.
options.algorithms = ['HS256'];
jwt.verify(token, process.env.TALK_SESSION_SECRET, options, (err, decoded) => {
jwt.verify(token, JWT_SECRET, options, (err, decoded) => {
if (err) {
return reject(err);
}
@@ -694,7 +688,7 @@ module.exports = class UsersService {
* @param {String} email The email that we are needing to get confirmed.
* @return {Promise}
*/
static createEmailConfirmToken(userID = null, email, referer = process.env.TALK_ROOT_URL) {
static createEmailConfirmToken(userID = null, email, referer = ROOT_URL) {
if (!email || typeof email !== 'string') {
return Promise.reject('email is required when creating a JWT for resetting passord');
}
@@ -737,7 +731,7 @@ module.exports = class UsersService {
email,
referer,
userID: user.id
}, process.env.TALK_SESSION_SECRET, tokenOptions);
}, JWT_SECRET, tokenOptions);
});
}
@@ -842,7 +836,7 @@ module.exports = class UsersService {
*/
static ignoreUsers(userId, usersToIgnore) {
assert(Array.isArray(usersToIgnore), 'usersToIgnore is an array');
assert(usersToIgnore.every(u => typeof u === 'string'), 'usersToIgnore is an array of string user IDs');
assert(usersToIgnore.every((u) => typeof u === 'string'), 'usersToIgnore is an array of string user IDs');
if (usersToIgnore.includes(userId)) {
throw new Error('Users cannot ignore themselves');
}
@@ -864,7 +858,7 @@ module.exports = class UsersService {
*/
static async stopIgnoringUsers(userId, usersToStopIgnoring) {
assert(Array.isArray(usersToStopIgnoring), 'usersToStopIgnoring is an array');
assert(usersToStopIgnoring.every(u => typeof u === 'string'), 'usersToStopIgnoring is an array of string user IDs');
assert(usersToStopIgnoring.every((u) => typeof u === 'string'), 'usersToStopIgnoring is an array of string user IDs');
await UserModel.update({id: userId}, {
$pullAll: {
ignoresUsers: usersToStopIgnoring