Qq fix pour corriger la page de login
This commit is contained in:
@@ -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;
|
||||
// },
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user