Commit a86a885c authored by Hamza HRAMCHI's avatar Hamza HRAMCHI
Browse files

FEAT #16956 TIME 1:10 get otp config

parent 4704b113
......@@ -5,9 +5,9 @@
<mat-spinner style="margin:auto;"></mat-spinner>
</div>
<div *ngIf="!loading" class="userForm">
<mat-form-field appearance="fill" *ngIf="sources.length >= 1">
<mat-form-field appearance="fill">
<mat-label>{{ 'lang.source' | translate }}</mat-label>
<mat-select #source [value]="userOTP.sourceId" required>
<mat-select #source [(ngModel)]="userOTP.sourceId" (selectionChange)="setCurrentSource($event.value)" required>
<mat-option *ngFor="let source of sources" [value]="source.id" >
{{ source.label }}
</mat-option>
......@@ -28,21 +28,21 @@
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>{{'lang.email' | translate}}</mat-label>
<input matInput #email type="email" [(ngModel)]="userOTP.email" pattern="[a-zA-Z0-9._%+-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$" required>
<input matInput #email type="email" [(ngModel)]="userOTP.email" pattern="(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)" required>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>{{'lang.role' | translate}}</mat-label>
<mat-select #role [(ngModel)]="userOTP.role" required>
<mat-option *ngFor="let role of sampleRoles" [value]="role.id" >
<mat-option *ngFor="let role of roles" [value]="role.id" >
{{ role.label }}
</mat-option>
</mat-select>
</mat-form-field>
<mat-form-field appearance="fill">
<mat-label>{{ 'lang.securityMode' | translate }}</mat-label>
<mat-select #securityMode [(ngModel)]="userOTP.security" required>
<mat-option *ngFor="let mode of securityModes" [value]="mode.id" >
{{ mode.label }}
<mat-select #securityMode [(ngModel)]="userOTP.security"required>
<mat-option *ngFor="let mode of currentSource" [value]="mode" >
{{ 'lang.' + mode | translate }}
</mat-option>
</mat-select>
</mat-form-field>
......
import { Component, Input, OnInit, Output, EventEmitter } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { TranslateService } from '@ngx-translate/core';
import { NotificationService } from '@service/notification/notification.service';
import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop';
import { FunctionsService } from '@service/functions.service';
import { tap, catchError } from 'rxjs/operators';
import { FormControl } from '@angular/forms';
import { ScanPipe } from 'ngx-pipes';
import { Observable, of } from 'rxjs';
import { MatDialogRef } from '@angular/material/dialog';
import { of } from 'rxjs';
@Component({
templateUrl: 'create-user-otp.component.html',
......@@ -17,22 +14,11 @@ import { MatDialogRef } from '@angular/material/dialog';
export class CreateUserOtpComponent implements OnInit {
// For TEST
sources: any[] = [];
sources: any[] = [
{
id: 1,
label: 'Yousign 1',
type: 'yousign'
},
{
id: 2,
label: 'Yousign 2',
type: 'yousign'
}
];
currentSource: any[] = [];
sampleRoles: any[] = [
roles: any[] = [
{
id: 'otp_visa_yousign',
label: this.translate.instant('lang.otp_visa_yousign')
......@@ -61,8 +47,8 @@ export class CreateUserOtpComponent implements OnInit {
phone: '',
role: '',
security: '',
sourceId: this.sources[0].id,
type: this.sources[0].type
sourceId: '',
type: ''
};
constructor(
......@@ -75,14 +61,16 @@ export class CreateUserOtpComponent implements OnInit {
) { }
async ngOnInit(): Promise<void> {
// await this.getConfig();
await this.getConfig();
}
getConfig() {
return new Promise((resolve) => {
this.http.get('../rest/maarchParapheurOtp').pipe(
tap((data: any) => {
console.log(data);
if (data) {
this.sources = data.otp;
}
resolve(true);
}),
catchError((err: any) => {
......@@ -103,7 +91,13 @@ export class CreateUserOtpComponent implements OnInit {
validFormat() {
const phoneRegex = /^(\+33)[1-9]{9}$/;
const emailReegex = /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9._-]+\.[a-zA-Z]{2,4}$/;
const emailReegex = /^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$/;
return (this.userOTP.phone.length > 1 && this.userOTP.phone.trim().match(phoneRegex) !== null) && (this.userOTP.email.length > 1 && this.userOTP.email.trim().match(emailReegex) !== null);
}
setCurrentSource(id: any) {
const selectedSource: any = this.sources.filter((item: any) => item.id === id)[0];
this.userOTP.type = selectedSource.type;
this.currentSource = selectedSource.securityModes;
}
}
<mat-list *ngIf="!loading">
<button *ngIf="adminMode" mat-raised-button mat-button color="primary" [title]="'lang.addOtpUser' | translate"
<button *ngIf="adminMode && otpConfig > 0" mat-raised-button mat-button color="primary" [title]="'lang.addOtpUser' | translate"
style="margin: 10px; display: flex;" (click)="openCreateUserOtp()">
<mat-icon class="fas fa-user-plus" style="width: auto;height: auto;"></mat-icon>
{{'lang.addOtpUser' | translate}}
......
......@@ -46,6 +46,8 @@ export class ExternalVisaWorkflowComponent implements OnInit {
loadedInConstructor: boolean = false;
otpConfig: number = 0;
constructor(
public translate: TranslateService,
public http: HttpClient,
......@@ -55,7 +57,9 @@ export class ExternalVisaWorkflowComponent implements OnInit {
public actionService: ActionsService
) { }
ngOnInit(): void { }
async ngOnInit(): Promise<void> {
await this.getOtpConfig();
}
drop(event: CdkDragDrop<string[]>) {
if (event.previousContainer === event.container) {
......@@ -369,4 +373,21 @@ export class ExternalVisaWorkflowComponent implements OnInit {
})
).subscribe();
}
getOtpConfig() {
return new Promise((resolve) => {
this.http.get('../rest/maarchParapheurOtp').pipe(
tap((data: any) => {
if (data) {
this.otpConfig = data.otp.length;
}
resolve(true);
}),
catchError((err: any) => {
this.notify.handleSoftErrors(err);
return of(false);
})
).subscribe();
});
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment