Only mobile phone is requested on signon and it's mandatory
MODIFY
src/assets/server/rest/v1/schemas/auth/auth-signon.json
src/assets/server/rest/v1/schemas/auth/auth-signon.json
"captcha": {
"$ref": "common#/definitions/captcha"
},
- "phone": {
- "$ref": "user#/definitions/phone"
- },
"mobile": {
"$ref": "user#/definitions/mobile"
},
"firstName",
"password",
"acceptEula",
- "captcha"
+ "captcha",
+ "mobile"
]
}

MODIFY
src/server/rest/v1/service/AuthService.ts
src/server/rest/v1/service/AuthService.ts
@@ -5,6 +5,7 @@ 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';
@@ -15,7 +16,6 @@ import Logging from '../../../../utils/Logging';
import NotificationHandler from '../../../../notification/NotificationHandler';
import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
-import SiteStorage from '../../../../storage/mongodb/SiteStorage';
import { StatusCodes } from 'http-status-codes';
import Tag from '../../../../types/Tag';
import TagStorage from '../../../../storage/mongodb/TagStorage';
@@ -120,7 +120,7 @@ export default class AuthService {
public static async handleRegisterUser(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Filter
- const filteredRequest = AuthValidator.getInstance().validateAuthSignOnReq(req.body);
+ const filteredRequest = AuthValidatorStorage.getInstance().validateAuthSignOn(req.body);
// Override
filteredRequest.status = UserStatus.PENDING;
if (!filteredRequest.locale) {
@@ -161,7 +161,6 @@ export default class AuthService {
newUser.firstName = filteredRequest.firstName;
newUser.locale = filteredRequest.locale;
newUser.mobile = filteredRequest.mobile;
- newUser.phone = filteredRequest.phone;
newUser.createdOn = new Date();
const verificationToken = Utils.generateToken(filteredRequest.email);
const endUserLicenseAgreement = await UserStorage.getEndUserLicenseAgreement(tenant, Utils.getLanguageFromLocale(newUser.locale));

MODIFY
src/server/rest/v1/validator/AuthValidator.ts
src/server/rest/v1/validator/AuthValidator.ts
@@ -8,7 +8,6 @@ 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'));
@@ -30,10 +29,6 @@ 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);
}

MODIFY
src/storage/mongodb/UserStorage.ts
src/storage/mongodb/UserStorage.ts
@@ -1015,7 +1015,6 @@ export default class UserStorage {
name: 'Unknown',
firstName: 'User',
mobile: '',
- phone: '',
email: '',
address: null,
createdBy: null,

ADD
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);
+ }
+}

MODIFY
src/types/requests/HttpUserRequest.ts
src/types/requests/HttpUserRequest.ts
@@ -82,8 +82,7 @@ export interface HttpRegisterUserRequest extends HttpLoginRequest {
captcha: string;
status: string;
locale: string;
- mobile?: string;
- phone?: string;
+ mobile: string;
}
export interface HttpVerifyEmailRequest {

Only mobile phone is requested on signon and it's mandatory