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;
}
let id;
let user;
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');
id = await Database.users.getID('email', email);
user = await Database.users.getUser('email', email);
if (user == -1) errors.addError(422, 'Unprocessable entity', 'There is no user with that email');
} else {
if (await Database.users.getID('username', username) == -1) errors.addError(422, 'Unprocessable entity', 'There is no user with that username');
id = await Database.users.getID('username', username);
user = await Database.users.getUser('username', username);
if (user == -1) errors.addError(422, 'Unprocessable entity', 'There is no user with that username');
}
if (errors.count() > 0) {
@@ -38,7 +38,6 @@ export class LoginController extends ControllerHandler {
return;
}
let user = await Database.users.getUserByID(id);
let match = await User.Password.compare(password, user.password);
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;
try {
@@ -81,7 +81,7 @@ export class UserTools extends BaseDatabase {
} else {
return -1
}
return user.id;
return user;
} catch (e) {
Logger.error(`An error occured while querying the id of a user where ${column} is ${search}: ${e}`);