Qq fix pour corriger la page de login
This commit is contained in:
@@ -1,4 +1,30 @@
|
||||
<form
|
||||
focusInvalidInput
|
||||
autocomplete="off"
|
||||
style="padding: 10px"
|
||||
(ngSubmit)="onCreateSubmit()"
|
||||
[formGroup]="createForm"
|
||||
>
|
||||
<mat-form-field>
|
||||
<mat-label>{{ "LoginCreateUser_Firstname" | translate }}</mat-label>
|
||||
<input
|
||||
type="text"
|
||||
matInput
|
||||
#firstname="matInput"
|
||||
formControlName="firstname"
|
||||
[ngClass]="{ 'is-invalid': submitted && formCtrls['firstname'].errors }"
|
||||
tabindex="0"
|
||||
/>
|
||||
<mat-error *ngIf="formCtrls['firstname'].hasError('required')">
|
||||
{{ "LoginCreateUser_FirstnameRequired" | translate }}
|
||||
</mat-error>
|
||||
<mat-error *ngIf="formCtrls['firstname'].hasError('minlength')">
|
||||
{{ "LoginCreateUser_FirstnamePattern" | translate }}
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</form>
|
||||
|
||||
<!-- <form
|
||||
[formGroup]="createForm"
|
||||
(ngSubmit)="onCreateSubmit()"
|
||||
autocomplete="off"
|
||||
@@ -7,7 +33,7 @@
|
||||
<p>
|
||||
<mat-form-field>
|
||||
<mat-label>{{ "LoginCreateUser_Firstname" | translate }}</mat-label>
|
||||
<!-- <input
|
||||
<input
|
||||
matInput
|
||||
type="text"
|
||||
formControlName="firstname"
|
||||
@@ -19,13 +45,13 @@
|
||||
</mat-error>
|
||||
<mat-error *ngIf="formCtrls['firstname'].hasError('minlength')">
|
||||
{{ "LoginCreateUser_FirstnamePattern" | translate }}
|
||||
</mat-error> -->
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</p>
|
||||
<p>
|
||||
<mat-form-field>
|
||||
<mat-label>{{ "LoginCreateUser_Lastname" | translate }}</mat-label>
|
||||
<!-- <input
|
||||
<input
|
||||
matInput
|
||||
type="text"
|
||||
formControlName="lastname"
|
||||
@@ -37,13 +63,13 @@
|
||||
</mat-error>
|
||||
<mat-error *ngIf="formCtrls['lastname'].hasError('minlength')">
|
||||
{{ "LoginCreateUser_LastnamePattern" | translate }}
|
||||
</mat-error> -->
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</p>
|
||||
<p>
|
||||
<mat-form-field>
|
||||
<mat-label>{{ "LoginCreateUser_Email" | translate }}</mat-label>
|
||||
<!-- <input
|
||||
<input
|
||||
matInput
|
||||
type="email"
|
||||
formControlName="email"
|
||||
@@ -55,13 +81,13 @@
|
||||
</mat-error>
|
||||
<mat-error *ngIf="formCtrls['email'].hasError('email')">
|
||||
{{ "LoginCreateUser_EmailPattern" | translate }}
|
||||
</mat-error> -->
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</p>
|
||||
<p>
|
||||
<mat-form-field>
|
||||
<mat-label>{{ "LoginCreateUser_Username" | translate }}</mat-label>
|
||||
<!-- <input
|
||||
<input
|
||||
matInput
|
||||
type="text"
|
||||
formControlName="username"
|
||||
@@ -73,13 +99,13 @@
|
||||
</mat-error>
|
||||
<mat-error *ngIf="formCtrls['username'].hasError('minlength')">
|
||||
{{ "LoginCreateUser_UsernamePattern" | translate }}
|
||||
</mat-error> -->
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</p>
|
||||
<p>
|
||||
<mat-form-field>
|
||||
<mat-label>{{ "LoginCreateUser_Password" | translate }}</mat-label>
|
||||
<!-- <input
|
||||
<input
|
||||
matInput
|
||||
type="password"
|
||||
formControlName="password"
|
||||
@@ -91,7 +117,7 @@
|
||||
</mat-error>
|
||||
<mat-error *ngIf="formCtrls['password'].hasError('pattern')">
|
||||
{{ "LoginCreateUser_PasswordPattern" | translate }}
|
||||
</mat-error> -->
|
||||
</mat-error>
|
||||
</mat-form-field>
|
||||
</p>
|
||||
|
||||
@@ -99,4 +125,4 @@
|
||||
{{ "LoginCreateUser_BtnLogin" | translate }}
|
||||
</button>
|
||||
<div *ngIf="error" class="alert alert-danger mt-3 mb-0">{{ error }}</div>
|
||||
</form>
|
||||
</form> -->
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Component, OnInit } from "@angular/core";
|
||||
import { Component, OnInit, ViewChild } from "@angular/core";
|
||||
import { Router, ActivatedRoute } from "@angular/router";
|
||||
import {
|
||||
FormBuilder,
|
||||
@@ -18,6 +18,7 @@ import { first } from "rxjs/operators";
|
||||
|
||||
import { AuthenticationService } from "../../services/authentication.service";
|
||||
import { User } from "../../models/user";
|
||||
import { MatInput, MatInputModule } from "@angular/material/input";
|
||||
|
||||
@Component({
|
||||
selector: "app-create-user",
|
||||
@@ -27,16 +28,18 @@ import { User } from "../../models/user";
|
||||
CommonModule,
|
||||
MatFormFieldModule,
|
||||
ReactiveFormsModule,
|
||||
MatInputModule,
|
||||
TranslateModule,
|
||||
TranslatePipe,
|
||||
],
|
||||
})
|
||||
export class CreateUserComponent implements OnInit {
|
||||
createForm: FormGroup;
|
||||
invalidForm = true;
|
||||
submitted = false;
|
||||
returnUrl: string;
|
||||
error = "";
|
||||
public createForm: FormGroup;
|
||||
public invalidForm = true;
|
||||
public submitted = false;
|
||||
public returnUrl: string;
|
||||
public error: string = "";
|
||||
@ViewChild("firstname") firstnameInput: MatInput;
|
||||
|
||||
constructor(
|
||||
private formBuilder: FormBuilder,
|
||||
@@ -51,22 +54,26 @@ export class CreateUserComponent implements OnInit {
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
this.firstnameInput.focus();
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.createForm = this.formBuilder.group(
|
||||
{
|
||||
username: ["", [Validators.required, Validators.minLength(3)]],
|
||||
password: [
|
||||
"",
|
||||
[
|
||||
Validators.required,
|
||||
Validators.pattern(
|
||||
"^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[@$!%*#?&-_|]).{8,}$"
|
||||
),
|
||||
],
|
||||
],
|
||||
firstname: ["", [Validators.required, Validators.minLength(3)]],
|
||||
lastname: ["", [Validators.required, Validators.minLength(3)]],
|
||||
email: ["", [Validators.required, Validators.email]],
|
||||
// username: ["", [Validators.required, Validators.minLength(3)]],
|
||||
// password: [
|
||||
// "",
|
||||
// [
|
||||
// Validators.required,
|
||||
// Validators.pattern(
|
||||
// "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[@$!%*#?&-_|]).{8,}$"
|
||||
// ),
|
||||
// ],
|
||||
// ],
|
||||
// lastname: ["", [Validators.required, Validators.minLength(3)]],
|
||||
// email: ["", [Validators.required, Validators.email]],
|
||||
},
|
||||
{ updateOn: "blur" }
|
||||
);
|
||||
@@ -80,33 +87,28 @@ export class CreateUserComponent implements OnInit {
|
||||
}
|
||||
|
||||
onCreateSubmit() {
|
||||
this.invalidForm = false;
|
||||
this.submitted = true;
|
||||
|
||||
if (this.createForm.invalid) {
|
||||
this.invalidForm = true;
|
||||
return;
|
||||
}
|
||||
|
||||
let createUser = new User();
|
||||
createUser.login = this.formCtrls["username"].value;
|
||||
createUser.password = this.formCtrls["password"].value;
|
||||
createUser.firstName = this.formCtrls["firstname"].value;
|
||||
createUser.lastName = this.formCtrls["lastname"].value;
|
||||
createUser.email = this.formCtrls["email"].value;
|
||||
createUser.language = this.translateService.getCurrentLang();
|
||||
|
||||
this.authenticationService
|
||||
.create(createUser)
|
||||
.pipe(first())
|
||||
.subscribe(
|
||||
(data) => {
|
||||
this.router.navigate([this.returnUrl]);
|
||||
},
|
||||
(error) => {
|
||||
this.error = error;
|
||||
this.invalidForm = false;
|
||||
}
|
||||
);
|
||||
// this.invalidForm = false;
|
||||
// this.submitted = true;
|
||||
// if (this.createForm.invalid) {
|
||||
// this.invalidForm = true;
|
||||
// return;
|
||||
// }
|
||||
// let createUser = new User();
|
||||
// createUser.login = this.formCtrls["username"].value;
|
||||
// createUser.password = this.formCtrls["password"].value;
|
||||
// createUser.firstName = this.formCtrls["firstname"].value;
|
||||
// createUser.lastName = this.formCtrls["lastname"].value;
|
||||
// createUser.email = this.formCtrls["email"].value;
|
||||
// createUser.language = this.translateService.getCurrentLang();
|
||||
// this.authenticationService
|
||||
// .create(createUser)
|
||||
// .pipe(first())
|
||||
// .subscribe({
|
||||
// complete: () => this.router.navigate([this.returnUrl]),
|
||||
// error: (error) => {
|
||||
// this.error = error.message;
|
||||
// this.invalidForm = false;
|
||||
// },
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,11 +29,11 @@ import { AuthenticationService } from "../../services/authentication.service";
|
||||
],
|
||||
})
|
||||
export class LoginUserComponent implements OnInit, AfterViewInit {
|
||||
loginForm: FormGroup;
|
||||
loading = false;
|
||||
submitted = false;
|
||||
returnUrl: string;
|
||||
error = "";
|
||||
public loginForm: FormGroup;
|
||||
public loading = false;
|
||||
public submitted = false;
|
||||
public returnUrl: string;
|
||||
public error: string = "";
|
||||
@ViewChild("username") userNameInput: MatInput;
|
||||
|
||||
constructor(
|
||||
@@ -68,7 +68,7 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
|
||||
return this.loginForm.controls;
|
||||
}
|
||||
|
||||
onLoginSubmit() {
|
||||
public onLoginSubmit() {
|
||||
this.submitted = true;
|
||||
|
||||
if (this.loginForm.valid) {
|
||||
@@ -79,15 +79,13 @@ export class LoginUserComponent implements OnInit, AfterViewInit {
|
||||
this.formCtrls["password"].value
|
||||
)
|
||||
.pipe(first())
|
||||
.subscribe(
|
||||
(data) => {
|
||||
this.router.navigate([this.returnUrl]);
|
||||
},
|
||||
(error) => {
|
||||
this.error = error;
|
||||
.subscribe({
|
||||
complete: () => this.router.navigate([this.returnUrl]),
|
||||
error: (error) => {
|
||||
this.error = error.message;
|
||||
this.loading = false;
|
||||
}
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,5 @@
|
||||
<div class="content">
|
||||
<mat-select
|
||||
(selectionChange)="switchLang($event)"
|
||||
[(value)]="selectedLanguageFlag"
|
||||
style="width: 60px; padding-left: 30px"
|
||||
>
|
||||
<mat-select-trigger>
|
||||
<img
|
||||
src="{{ 'assets/img/' + selectedLanguageFlag + '.svg' }}"
|
||||
style="width: 30px"
|
||||
/>
|
||||
</mat-select-trigger>
|
||||
<mat-option value="fr">
|
||||
<img src="assets/img/fr.svg" style="width: 30px" />
|
||||
</mat-option>
|
||||
<mat-option value="en">
|
||||
<img src="assets/img/en.svg" style="width: 30px" />
|
||||
</mat-option>
|
||||
</mat-select>
|
||||
<app-create-user></app-create-user>
|
||||
|
||||
<!-- <mat-card style="max-width: 500px" flex="50">
|
||||
<mat-card style="max-width: 500px" flex="50">
|
||||
<mat-card-header
|
||||
style="
|
||||
align-items: center;
|
||||
@@ -59,5 +39,5 @@
|
||||
</mat-tab>
|
||||
</mat-tab-group>
|
||||
</mat-card-content>
|
||||
</mat-card> -->
|
||||
</mat-card>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user