modification messageService

This commit is contained in:
MiharyR 2021-12-04 11:09:37 +01:00
parent 819d266601
commit 6444df567b
4 changed files with 56 additions and 30 deletions

View file

@ -42,12 +42,29 @@ export class PageLoginComponent implements OnInit
hashPass: this.hashage(this.password)
};
this.messageService
.sendMessage('user/auth', data)
.subscribe( retour => this.maCallback(retour))
.post('user/auth', data)
.subscribe( retour => this.onSeConnecterCallback(retour));
}
}
onSeConnecterCallback(retour): void
{
console.log(retour);
if(retour.status !== 200)
{
console.log("noooo !");
//this.errorMessage = retour.error.data.reason;
//this.hasError = true;
}
else {
console.log("yeeess !");
//this.router.navigateByUrl( '/search' );
}
}
onForgottenPassword(): void
{
this.dialog
@ -63,19 +80,6 @@ export class PageLoginComponent implements OnInit
}
maCallback(retour): void
{
console.log(retour.data)
if(retour.status !== 200) {
this.errorMessage = retour.error.data.reason;
this.hasError = true;
}
else {
//this.router.navigateByUrl( '/search' );
}
}
checkError(): void
{
if(this.email === "") {

View file

@ -3,16 +3,38 @@ import {HttpClient} from "@angular/common/http";
import {environment} from "../../../../environments/environment";
import {Observable} from "rxjs";
@Injectable({
providedIn: 'root'
})
export class MessageService
{
constructor( private http: HttpClient ) { }
sendMessage( url, data ): Observable<any>
post(url: string, data: any): Observable<any>
{
const urlComplete = environment.debutUrl + url ;
return this.http.post<any>( urlComplete, data, {withCredentials: true} );
return this.http.post<any>(urlComplete, data, {withCredentials: true});
}
get(url: string, data: any): Observable<any>
{
const urlComplete = environment.debutUrl + url ;
return this.http.get<any>(urlComplete, data);
}
put(url: string, data: any): Observable<any>
{
const urlComplete = environment.debutUrl + url ;
return this.http.put<any>(urlComplete, data, {withCredentials: true});
}
delete(url: string, data: any): Observable<any>
{
const urlComplete = environment.debutUrl + url ;
return this.http.delete<any>(urlComplete, data);
}
}