put back AuthValidator
MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -5,7 +5,6 @@ import User, { UserRole, UserStatus } from '../../../../types/User';
import AppError from '../../../../exception/AppError';
import AuthValidator from '../validator/AuthValidator';
-import AuthValidatorStorage from '../../../../storage/mongodb/validator/AuthValidatorStorage';
import Authorizations from '../../../../authorization/Authorizations';
import BillingFactory from '../../../../integration/billing/BillingFactory';
import Configuration from '../../../../utils/Configuration';
@@ -120,7 +119,7 @@ export default class AuthService {
public static async handleRegisterUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthValidatorStorage.getInstance().validateAuthSignOn(req.body);
+ const filteredRequest = AuthValidator.getInstance().validateAuthSignOnReq(req.body);
// Override
filteredRequest.status = UserStatus.PENDING;
if (!filteredRequest.locale) {

MODIFY
src/server/rest/v1/validator/AuthValidator.ts
src/server/rest/v1/validator/AuthValidator.ts
-import { HttpCheckEulaRequest, HttpEulaRequest, HttpLoginRequest, HttpResendVerificationMailRequest, HttpResetPasswordRequest, HttpVerifyEmailRequest } from '../../../../types/requests/HttpUserRequest';
+import { HttpCheckEulaRequest, HttpEulaRequest, HttpLoginRequest, HttpRegisterUserRequest, HttpResendVerificationMailRequest, HttpResetPasswordRequest, HttpVerifyEmailRequest } from '../../../../types/requests/HttpUserRequest';
import Schema from '../../../../types/validator/Schema';
import SchemaValidator from '../../../../validator/SchemaValidator';
@@ -8,6 +8,7 @@ import global from '../../../../types/GlobalType';
export default class AuthValidator extends SchemaValidator {
private static instance: AuthValidator | null = null;
private authSignIn: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-signin.json`, 'utf8'));
+ private authSignOn: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-signon.json`, 'utf8'));
private authPasswordReset: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-password-reset.json`, 'utf8'));
private authEulaCheck: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-eula-check.json`, 'utf8'));
private authEmailVerify: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-email-verify.json`, 'utf8'));
@@ -15,7 +16,14 @@ export default class AuthValidator extends SchemaValidator {
private authEula: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-eula.json`, 'utf8'));
private constructor() {
- super('AuthValidator');
+ super('AuthValidator', {
+ strict: true, // When 'true', it fails with anyOf required fields: https://github.com/ajv-validator/ajv/issues/1571
+ allErrors: true,
+ removeAdditional: true, // 'all' fails with anyOf documents: Manually added 'additionalProperties: false' in schema due filtering of data in anyOf/oneOf/allOf array (it's standard): https://github.com/ajv-validator/ajv/issues/1784
+ allowUnionTypes: true,
+ coerceTypes: true,
+ verbose: true,
+ });
}
public static getInstance(): AuthValidator {
@@ -29,6 +37,10 @@ export default class AuthValidator extends SchemaValidator {
return this.validate(this.authSignIn, data);
}
+ public validateAuthSignOnReq(data: Record<string, unknown>): Partial<HttpRegisterUserRequest> {
+ return this.validate(this.authSignOn, data);
+ }
+
public validateAuthPasswordResetReq(data: Record<string, unknown>): Partial<HttpResetPasswordRequest> {
return this.validate(this.authPasswordReset, data);
}

DELETE
src/storage/mongodb/validator/AuthValidatorStorage.ts
-import { ChargingStationTemplate } from '../../../types/ChargingStation';
-import { HttpRegisterUserRequest } from '../../../types/requests/HttpUserRequest';
-import Schema from '../../../types/validator/Schema';
-import SchemaValidator from '../../../validator/SchemaValidator';
-import fs from 'fs';
-import global from '../../../types/GlobalType';
-
-export default class AuthValidatorStorage extends SchemaValidator {
- private static instance: AuthValidatorStorage | null = null;
- private authSignOn: Schema = JSON.parse(fs.readFileSync(`${global.appRoot}/assets/server/rest/v1/schemas/auth/auth-signon.json`, 'utf8'));
-
- private constructor() {
- super('AuthValidatorStorage', {
- strict: true, // When 'true', it fails with anyOf required fields: https://github.com/ajv-validator/ajv/issues/1571
- allErrors: true,
- removeAdditional: true, // 'all' fails with anyOf documents: Manually added 'additionalProperties: false' in schema due filtering of data in anyOf/oneOf/allOf array (it's standard): https://github.com/ajv-validator/ajv/issues/1784
- allowUnionTypes: true,
- coerceTypes: true,
- verbose: true,
- });
- }
-
- public static getInstance(): AuthValidatorStorage {
- if (!AuthValidatorStorage.instance) {
- AuthValidatorStorage.instance = new AuthValidatorStorage();
- }
- return AuthValidatorStorage.instance;
- }
-
- public validateAuthSignOn(data: any): Partial<HttpRegisterUserRequest> {
- return this.validate(this.authSignOn, data);
- }
-}

put back AuthValidator