Aligned HTTP Error and return correct code to the UI
MODIFY
src/server/rest/service/AuthService.ts
src/server/rest/service/AuthService.ts
@@ -138,7 +138,7 @@ export default class AuthService {
// Return data
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.USER_LOCKED_ERROR,
+ errorCode: HTTPError.USER_ACCOUNT_LOCKED_ERROR,
message: 'User is locked',
module: MODULE_NAME,
method: 'handleLogIn'
@@ -830,7 +830,7 @@ export default class AuthService {
// Log
throw new AppError({
source: Constants.CENTRAL_SERVER,
- errorCode: HTTPError.USER_LOCKED_ERROR,
+ errorCode: HTTPError.USER_ACCOUNT_LOCKED_ERROR,
message: 'User is locked',
module: MODULE_NAME,
method: 'checkUserLogin',
@@ -922,10 +922,11 @@ export default class AuthService {
if (user.password) {
match = await Utils.checkPasswordBCrypt(filteredRequest.password, user.password);
}
- // Check new and old version of hashing the password
+ // Check password hash
if (match || (user.password === Utils.hashPassword(filteredRequest.password))) {
- // Check if the account is pending
- if (user.status === UserStatus.PENDING) {
+ // Check status
+ switch (user.status) {
+ case UserStatus.PENDING:
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.USER_ACCOUNT_PENDING_ERROR,
@@ -934,13 +935,29 @@ export default class AuthService {
method: 'checkUserLogin',
user: user
});
- }
- // Check if the account is active
- if (user.status !== UserStatus.ACTIVE) {
+ case UserStatus.LOCKED:
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.USER_ACCOUNT_LOCKED_ERROR,
+ message: `Account is locked ('${user.status}')`,
+ module: MODULE_NAME,
+ method: 'checkUserLogin',
+ user: user
+ });
+ case UserStatus.INACTIVE:
throw new AppError({
source: Constants.CENTRAL_SERVER,
errorCode: HTTPError.USER_ACCOUNT_INACTIVE_ERROR,
- message: `Account is not active ('${user.status}')`,
+ message: `Account is inactive ('${user.status}')`,
+ module: MODULE_NAME,
+ method: 'checkUserLogin',
+ user: user
+ });
+ case UserStatus.BLOCKED:
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.USER_ACCOUNT_BLOCKED_ERROR,
+ message: `Account is blocked ('${user.status}')`,
module: MODULE_NAME,
method: 'checkUserLogin',
user: user

MODIFY
src/types/HTTPError.ts
src/types/HTTPError.ts
@@ -19,12 +19,14 @@ export enum HTTPError {
USER_EMAIL_ALREADY_EXIST_ERROR = 510,
USER_EULA_ERROR = 520,
- USER_ACCOUNT_ALREADY_ACTIVE_ERROR = 530,
USER_TAG_ID_ALREADY_USED_ERROR = 540,
- USER_LOCKED_ERROR = 570,
USER_NO_BADGE_ERROR = 570,
- USER_ACCOUNT_INACTIVE_ERROR = 580,
- USER_ACCOUNT_PENDING_ERROR = 590,
+
+ USER_ACCOUNT_LOCKED_ERROR = 590,
+ USER_ACCOUNT_ALREADY_ACTIVE_ERROR = 591,
+ USER_ACCOUNT_PENDING_ERROR = 592,
+ USER_ACCOUNT_BLOCKED_ERROR = 593,
+ USER_ACCOUNT_INACTIVE_ERROR = 594,
INVALID_CAPTCHA = 530,
INVALID_TOKEN_ERROR = 540,

Aligned HTTP Error and return correct code to the UI