Page de connexion presque prête. Il manque la redirection de page en fonction du role

This commit is contained in:
MiharyR 2021-10-26 09:11:17 +02:00
parent 0c4142035b
commit fd24009f87
16 changed files with 249 additions and 48 deletions

View file

@ -0,0 +1,84 @@
import { Component, OnInit } from '@angular/core';
import {MessageService} from "../../outils/message/message.service";
import {Router} from "@angular/router";
import {MatDialog} from "@angular/material/dialog";
import {PopupConfirmationComponent} from "../popup-confirmation/popup-confirmation.component";
@Component({
selector: 'app-page-register',
templateUrl: './page-register.component.html',
styleUrls: ['./page-register.component.scss']
})
export class PageRegisterComponent implements OnInit
{
pseudo: string = "";
email: string = "" ;
password: string = "";
confirmPassword: string = "";
hasError: boolean = false;
errorMessage: string = "";
constructor( private messageService: MessageService,
private router: Router,
public dialog: MatDialog ) { }
ngOnInit(): void {}
verifierChamps(): void
{
if(this.pseudo.length === 0) {
this.errorMessage = "Veuillez remplir le champ 'pseudo'"
this.hasError = true;
}
else if(this.email.length === 0)
{
this.errorMessage = "Veuillez remplir le champ 'email'"
this.hasError = true;
}
else if(this.password.length === 0)
{
this.errorMessage = "Veuillez remplir le champ 'mot de passe'"
this.hasError = true;
}
else if(this.password !== this.confirmPassword)
{
this.errorMessage = "Le mot de passe est différent de sa confirmation"
this.hasError = true;
}
else {
this.hasError = false;
}
}
onValider(): void
{
this.verifierChamps()
console.log(this.hasError)
if(!this.hasError)
{
let data = { "pseudo": this.pseudo, "email": this.email, "password": this.password }
this.messageService
.sendMessage('register', data)
.subscribe(retour => this.maCallback(retour))
}
}
maCallback(retour): void
{
if(retour.status === "error") console.log(retour.data)
else
{
const config = { width: '25%', data: {} }
this.dialog
.open(PopupConfirmationComponent, config )
.afterClosed()
.subscribe(result => this.router.navigateByUrl( '/connexion' ));
}
}
}