connexion avec le backend pour la page login

This commit is contained in:
MiharyR 2022-01-13 12:13:04 +01:00
parent 9566d11dd7
commit 22f6d316b4
5 changed files with 78 additions and 18 deletions

View file

@ -1,7 +1,7 @@
import {Component} from '@angular/core';
import {Router} from "@angular/router";
import {MessageService} from "../../common/services/message/message.service";
import {HashageService} from "../../common/services/hashage/hashage.service";
import {ProfilService} from "../../common/services/profil/profil.service";
@ -20,7 +20,7 @@ export class PageLoginComponent
constructor( private messageService: MessageService,
private router: Router,
private hashageService: HashageService ) { }
private profilService: ProfilService ) { }
// Appuie sur le bouton "seConnecter"
@ -29,30 +29,31 @@ export class PageLoginComponent
this.checkField();
if(!this.hasError)
{
let data = {
const data = {
email: this.email,
hash_pass: this.hashageService.run(this.password)
password: this.password
};
console.log(data);
/*
this.messageService
.sendMessage('user/auth', data)
.subscribe( retour => this.callbackSeConnecter(retour))
*/
.post('login', data)
.subscribe( retour => this.onSeConnecterCallback(retour), err => this.onSeConnecterCallback(err));
}
}
// Callback de "onSeConnecter"
callbackSeConnecter(retour: any): void
onSeConnecterCallback(retour: any): void
{
if(retour.status !== 200)
console.log(retour);
if(retour.status !== "success")
{
this.errorMessage = retour.error.data.reason;
this.errorMessage = retour.message;
this.hasError = true;
}
else {
//this.router.navigateByUrl( '/search' );
this.profilService.setId(retour.data.id);
this.profilService.setIsAdmin(retour.data.is_admin)
if(!retour.data.is_admin) this.router.navigateByUrl('admin/userList');
else this.router.navigateByUrl('user/userList');
}
}