Merge branch 'email-auth-gdpr' of github.com:coralproject/talk into email-auth-gdpr

* 'email-auth-gdpr' of github.com:coralproject/talk:
  added docs
  Added TALK_ prefix to constants RECAPTCHA_WINDOW and RECAPTCHA_INCORRECT_TRIGGER
  cleaned up refs to passwor dhash
  RECAPTCHA_WINDOW and RECAPTCHA_INCORRECT_TRIGGER now can be set with env vars
This commit is contained in:
okbel
2018-05-03 16:25:17 -03:00
4 changed files with 33 additions and 9 deletions
+7
View File
@@ -212,6 +212,13 @@ const CONFIG = {
RECAPTCHA_PUBLIC: process.env.TALK_RECAPTCHA_PUBLIC,
RECAPTCHA_SECRET: process.env.TALK_RECAPTCHA_SECRET,
// RECAPTCHA_WINDOW is the rate limit's time interval
RECAPTCHA_WINDOW: process.env.TALK_RECAPTCHA_WINDOW || '10m',
// After RECAPTCHA_INCORRECT_TRIGGER incorrect attempts, recaptcha will be required.
RECAPTCHA_INCORRECT_TRIGGER:
process.env.TALK_RECAPTCHA_INCORRECT_TRIGGER || 5,
// WEBSOCKET_LIVE_URI is the absolute url to the live endpoint.
WEBSOCKET_LIVE_URI: process.env.TALK_WEBSOCKET_LIVE_URI || null,
+13 -1
View File
@@ -316,6 +316,18 @@ default to providing only a time based lockout. Refer to
[reCAPTCHA](https://www.google.com/recaptcha/intro/index.html) for information
on getting an account setup.
## TALK_RECAPTCHA_WINDOW
The rate limit time interval that there can be [TALK_RECAPTCHA_INCORRECT_TRIGGER](#talk_recaptcha_incorrect_trigger) incorrect attempts until the reCAPTCHA is
marked as required, parsed by
[ms](https://www.npmjs.com/package/ms). (Default `10m`)
## TALK_RECAPTCHA_INCORRECT_TRIGGER
The number of times that an incorrect login can be entered before within a time
perioud indicated by [TALK_RECAPTCHA_WINDOW](#talk_recaptcha_window) until the
reCAPTCHA is marked as required. (Default `5`)
## TALK_REDIS_CLIENT_CONFIGURATION
Configuration overrides for the redis client configuration in a JSON encoded
@@ -531,4 +543,4 @@ Sets the logging level for the context logger (from [Bunyan](https://github.com/
A JSON string representing the configuration passed to the
[fetch](https://www.npmjs.com/package/node-fetch) call for the scraper. It
can be used to set an authorization header, or change the user agent. (Default
`{}`)
`{}`)
@@ -5,7 +5,6 @@ const {
ErrIncorrectPassword,
} = require('./errors');
const { get } = require('lodash');
const bcrypt = require('bcryptjs');
// hasLocalProfile checks a user's profiles to see if they already have a local
// profile associated with their account.
@@ -88,7 +87,7 @@ async function attachUserLocalAuth(ctx, email, password) {
await Users.isValidPassword(password);
// Hash the new password.
const hashedPassword = await bcrypt.hash(password, 10);
const hashedPassword = await Users.hashPassword(password);
try {
// Associate the account with the user.
+12 -6
View File
@@ -18,12 +18,14 @@ const {
ErrCannotIgnoreStaff,
} = require('../errors');
const { difference, sample, some, merge, random } = require('lodash');
const { ROOT_URL } = require('../config');
const {
ROOT_URL,
RECAPTCHA_WINDOW,
RECAPTCHA_INCORRECT_TRIGGER,
} = require('../config');
const { jwt: JWT_SECRET } = require('../secrets');
const debug = require('debug')('talk:services:users');
const User = require('../models/user');
const RECAPTCHA_WINDOW = '10m'; // 10 minutes.
const RECAPTCHA_INCORRECT_TRIGGER = 5; // after 5 incorrect attempts, recaptcha will be required.
const Actions = require('./actions');
const mailer = require('./mailer');
const i18n = require('./i18n');
@@ -557,7 +559,7 @@ class Users {
throw new ErrPasswordTooShort();
}
const hashedPassword = await bcrypt.hash(password, SALT_ROUNDS);
const hashedPassword = await Users.hashPassword(password);
return User.update(
{ id },
@@ -634,7 +636,7 @@ class Users {
Users.isValidPassword(password),
]);
const hashedPassword = await bcrypt.hash(password, SALT_ROUNDS);
const hashedPassword = await Users.hashPassword(password);
let user = new User({
username,
@@ -811,6 +813,10 @@ class Users {
return { user, redirect, version };
}
static async hashPassword(password) {
return bcrypt.hash(password, SALT_ROUNDS);
}
// TODO: update doc
static async resetPassword(token, password) {
const { user, redirect, version } = await this.verifyPasswordResetToken(
@@ -821,7 +827,7 @@ class Users {
throw new ErrPasswordTooShort();
}
const hashedPassword = await bcrypt.hash(password, SALT_ROUNDS);
const hashedPassword = await Users.hashPassword(password);
// Update the user's password.
await User.update(