mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
Suggestions for refactoring
This commit is contained in:
+4
-14
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user