Suggestions for refactoring

This commit is contained in:
Wyatt Johnson
2017-07-25 12:32:15 +10:00
parent aeeafb6284
commit c2f6b9aa09
9 changed files with 57 additions and 58 deletions
+4 -14
View File
@@ -30,17 +30,7 @@ const PASSWORD_RESET_JWT_SUBJECT = 'password_reset';
const SALT_ROUNDS = 10;
// Create a redis client to use for authentication.
const {createClient} = require('./redis');
let _client = null;
const getClient = () => {
if (_client) {
return _client;
}
_client = createClient();
return _client;
};
const {createClientFactory} = require('./redis');
// UsersService is the interface for the application to interact with the
// UserModel through.
@@ -77,7 +67,7 @@ module.exports = class UsersService {
const rdskey = `la[${email.toLowerCase().trim()}]`;
return new Promise((resolve, reject) => {
getClient()
createClientFactory()
.multi()
.incr(rdskey)
.expire(rdskey, RECAPTCHA_WINDOW_SECONDS)
@@ -90,7 +80,7 @@ module.exports = class UsersService {
if (replies[0] === 1 || replies[1] === -1) {
// then expire it after the timeout
getClient().expire(rdskey, RECAPTCHA_WINDOW_SECONDS);
createClientFactory().expire(rdskey, RECAPTCHA_WINDOW_SECONDS);
}
if (replies[0] >= RECAPTCHA_INCORRECT_TRIGGER) {
@@ -112,7 +102,7 @@ module.exports = class UsersService {
const rdskey = `la[${email.toLowerCase().trim()}]`;
return new Promise((resolve, reject) => {
getClient()
createClientFactory()
.get(rdskey, (err, reply) => {
if (err) {
return reject(err);