Merge branch 'refs/heads/feature/SUPPORT-8971_validation' into SUPPORT-8943_seamlessness
This commit is contained in:
commit
bdb112c211
12 changed files with 207 additions and 55 deletions
|
|
@ -16,6 +16,5 @@
|
|||
"password_pattern": "^((?=(.*\\d){1,})(?=.*[a-zа-яё])(?=.*[A-ZА-ЯЁ]).{8,})$",
|
||||
"password_pattern_error": "Пароль должен содержать заглавные или прописные буквы и как минимум 1 цифру",
|
||||
"show.client.errors": false,
|
||||
"available_task.single_fetch": true,
|
||||
"ervu_url": "https://ervu-dev.pgs.rtlabs.ru/service"
|
||||
"available_task.single_fetch": true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import {Observable, throwError} from 'rxjs';
|
||||
import {catchError, map} from "rxjs/operators";
|
||||
import {AppConfigService} from "@webbpm/base-package";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class IdmService {
|
||||
private ervuUrl: string;
|
||||
|
||||
constructor(private http: HttpClient, appConfigService: AppConfigService) {
|
||||
this.ervuUrl = appConfigService.getParamValue("ervu_url");
|
||||
}
|
||||
|
||||
checkLoginExists(login: string): Observable<boolean> {
|
||||
const url = `${this.ervuUrl}/idm/credentials/login/${login}`;
|
||||
return this.http.get<any[]>(url).pipe(
|
||||
map(response =>
|
||||
response.length > 0 && response.some(user => user.userName === login)
|
||||
),
|
||||
catchError(error => throwError(error))
|
||||
);
|
||||
}
|
||||
|
||||
checkSnilsExists(snils: string): Observable<boolean> {
|
||||
const url = `${this.ervuUrl}/idm/persons?query=snils%3D%3D%22${snils}%22`;
|
||||
return this.http.get<{ records: any[] }>(url).pipe(
|
||||
map(response =>
|
||||
response.records.length > 0 && response.records.some(person => person.snils === snils)
|
||||
),
|
||||
catchError(error => throwError(error))
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,19 +1,20 @@
|
|||
import {SimpleValidator, TextField} from "@webbpm/base-package";
|
||||
import {Observable} from "rxjs";
|
||||
import {IdmService} from "../IdmService";
|
||||
import {
|
||||
IdmValidatorRpcService
|
||||
} from "../../../generated/ru/micord/ervu/account_applications/component/rpc/IdmValidatorRpcService";
|
||||
|
||||
export abstract class AbstractIdmValidator extends SimpleValidator {
|
||||
protected abstract ERROR_MESSAGE: string;
|
||||
protected abstract checkValueExists(value: string): Observable<boolean>;
|
||||
protected abstract checkValueExists(value: string): Promise<boolean>;
|
||||
|
||||
protected textField: TextField;
|
||||
protected idmService: IdmService;
|
||||
protected rpcService: IdmValidatorRpcService;
|
||||
protected textInput: HTMLInputElement;
|
||||
|
||||
initialize(): void {
|
||||
super.initialize();
|
||||
this.textField = this.getScript(TextField);
|
||||
this.idmService = this.injector.get(IdmService);
|
||||
this.rpcService = this.getScript(IdmValidatorRpcService);
|
||||
this.textInput = this.textField.getEl().nativeElement.querySelector('input');
|
||||
this.textInput.addEventListener('blur', this.onBlurHandler.bind(this));
|
||||
}
|
||||
|
|
@ -25,17 +26,16 @@ export abstract class AbstractIdmValidator extends SimpleValidator {
|
|||
const cleanedValue = this.cleanValue(inputValue);
|
||||
if (!this.isPatternValid(cleanedValue)) return Promise.resolve(false);
|
||||
|
||||
return this.checkValueExists(cleanedValue).toPromise().then(
|
||||
(exists) => {
|
||||
return this.checkValueExists(cleanedValue)
|
||||
.then(exists => {
|
||||
this.pushError(!exists, this.ERROR_MESSAGE);
|
||||
return !exists;
|
||||
},
|
||||
(err) => {
|
||||
})
|
||||
.catch(err => {
|
||||
const fieldName = this.textField.getObjectName();
|
||||
console.error(`Ошибка проверки ${fieldName}: ${err.message}`);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
private async onBlurHandler(event: FocusEvent): Promise<void> {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import {Observable} from "rxjs";
|
||||
import {AbstractIdmValidator} from "./AbstractIdmValidator";
|
||||
|
||||
export class IdmLoginValidator extends AbstractIdmValidator {
|
||||
protected ERROR_MESSAGE = "Пользователь с указанным логином уже существует";
|
||||
|
||||
protected checkValueExists(value: string): Observable<boolean> {
|
||||
return this.idmService.checkLoginExists(value);
|
||||
protected checkValueExists(value: string): Promise<boolean> {
|
||||
return this.rpcService.valueExists(value);
|
||||
}
|
||||
|
||||
protected isPatternValid(value: string): boolean {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
import {Observable} from "rxjs";
|
||||
import {AbstractIdmValidator} from "./AbstractIdmValidator";
|
||||
|
||||
export class IdmSnilsValidator extends AbstractIdmValidator {
|
||||
protected ERROR_MESSAGE = "Пользователь с указанным СНИЛС уже существует";
|
||||
|
||||
protected checkValueExists(value: string): Observable<boolean> {
|
||||
return this.idmService.checkSnilsExists(value);
|
||||
protected checkValueExists(value: string): Promise<boolean> {
|
||||
return this.rpcService.valueExists(value);
|
||||
}
|
||||
|
||||
protected cleanValue(value: string): string {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue