optomised login dir

This commit is contained in:
plane000
2018-09-04 18:17:33 +01:00
parent 2a2b422bf2
commit 558e550a3b
3 changed files with 1197 additions and 1198 deletions

2380
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -23,13 +23,13 @@ export class LoginController extends ControllerHandler {
return; return;
} }
let id; let user;
if (!username /*If they're loging in with email*/) { if (!username /*If they're loging in with email*/) {
if (await Database.users.getID('email', email) == -1) errors.addError(422, 'Unprocessable entity', 'There is no user with that email'); user = await Database.users.getUser('email', email);
id = await Database.users.getID('email', email); if (user == -1) errors.addError(422, 'Unprocessable entity', 'There is no user with that email');
} else { } else {
if (await Database.users.getID('username', username) == -1) errors.addError(422, 'Unprocessable entity', 'There is no user with that username'); user = await Database.users.getUser('username', username);
id = await Database.users.getID('username', username); if (user == -1) errors.addError(422, 'Unprocessable entity', 'There is no user with that username');
} }
if (errors.count() > 0) { if (errors.count() > 0) {
@@ -38,7 +38,6 @@ export class LoginController extends ControllerHandler {
return; return;
} }
let user = await Database.users.getUserByID(id);
let match = await User.Password.compare(password, user.password); let match = await User.Password.compare(password, user.password);
if (!match) errors.addError(401, 'Unauthorized', 'Incorrect password for user'); if (!match) errors.addError(401, 'Unauthorized', 'Incorrect password for user');

View File

@@ -56,7 +56,7 @@ export class UserTools extends BaseDatabase {
} }
} }
static async getID(column, search) { static async getUser(column, search) {
let User = BaseDatabase.User; let User = BaseDatabase.User;
try { try {
@@ -81,7 +81,7 @@ export class UserTools extends BaseDatabase {
} else { } else {
return -1 return -1
} }
return user.id; return user;
} catch (e) { } catch (e) {
Logger.error(`An error occured while querying the id of a user where ${column} is ${search}: ${e}`); Logger.error(`An error occured while querying the id of a user where ${column} is ${search}: ${e}`);