refactor Utils package
This commit is contained in:
@@ -5,6 +5,7 @@ import { v4 as uuidv4 } from 'uuid';
|
||||
import { Strategy as LocalStrategy } from 'passport-local';
|
||||
import { Strategy as FacebookStrategy } from 'passport-facebook';
|
||||
import { Strategy as GoogleStrategy } from 'passport-google-oauth20';
|
||||
import Utils from '../Utils.js';
|
||||
|
||||
const collection = 'users';
|
||||
const emailRegexp = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
||||
@@ -31,16 +32,16 @@ class UserManager {
|
||||
|
||||
passport.use(new LocalStrategy({ usernameField: 'email', passwordField: 'password' },
|
||||
async function (email, password, done) {
|
||||
let user = await db.get(collection, { email: { $regex: `^${global.JsUtils.escapeRegExp(email)}$`, $options: 'i' } });
|
||||
let user = await db.get(collection, { email: { $regex: `^${Utils.escapeRegExp(email)}$`, $options: 'i' } });
|
||||
if (user) {
|
||||
if (md5(md5(password) + config.am.salt) == user.password) {
|
||||
return done(null, am.getUserProfile(user));
|
||||
} else {
|
||||
await global.JsUtils.wait(3000);
|
||||
await Utils.wait(3000);
|
||||
return done(null, false, { message: 'invalidPassword' });
|
||||
}
|
||||
} else {
|
||||
await global.JsUtils.wait(3000);
|
||||
await Utils.wait(3000);
|
||||
return done(null, false, { message: 'invalidUsername' });
|
||||
}
|
||||
}
|
||||
@@ -130,7 +131,7 @@ class UserManager {
|
||||
if (!emailRegexp.test(data.email)) {
|
||||
return reject(new Error('invalidEmail'));
|
||||
}
|
||||
let exists = await db.get(collection, { email: { $regex: `^${global.JsUtils.escapeRegExp(data.email)}$`, $options: 'i' } });
|
||||
let exists = await db.get(collection, { email: { $regex: `^${Utils.escapeRegExp(data.email)}$`, $options: 'i' } });
|
||||
if (exists) {
|
||||
return reject(new Error('emailExists'))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user