74 lines
1.9 KiB
TypeScript
74 lines
1.9 KiB
TypeScript
import { HttpClient, HttpHeaders } from '@angular/common/http';
|
|
import { identifierModuleUrl } from '@angular/compiler';
|
|
import { Injectable } from '@angular/core';
|
|
import { map, Observable } from 'rxjs';
|
|
import { environment } from 'src/environments/environment';
|
|
import { Membre } from '../models/membre';
|
|
import { Team } from '../models/team';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class AuthService {
|
|
private apiUrl: string;
|
|
private tokenKey: string;
|
|
|
|
constructor(private http: HttpClient) {
|
|
|
|
this.apiUrl = environment.apiUrl;
|
|
this.tokenKey = environment.tokenKey;
|
|
}
|
|
|
|
signup(membre: Membre): Observable<any> {
|
|
console.log(membre);
|
|
|
|
return this.http.post(`${this.apiUrl}/membres/sign-up`, membre);
|
|
|
|
}
|
|
|
|
|
|
signin(email: string, password: string): Observable<any> {
|
|
const body = {
|
|
email: email,
|
|
password: password,
|
|
};
|
|
|
|
console.log('Mon body : ', body);
|
|
return this.http.post(`${this.apiUrl}/membres/sign-in`, body).pipe(
|
|
map((x: any) => {
|
|
console.log('Service : ', x.token);
|
|
localStorage.setItem(this.tokenKey, x.token);
|
|
return x; // permet de renvoyer la réponse à l'initiateur (page Signin) après le traitement du map
|
|
})
|
|
);
|
|
|
|
}
|
|
|
|
forgotPassword(email: string): Observable<any> {
|
|
const body = {
|
|
email: email,
|
|
};
|
|
return this.http.get(`${this.apiUrl}/membres/forgot-password`);
|
|
}
|
|
|
|
resetPassword(email: string, password: string): Observable<any> {
|
|
const body = password;
|
|
console.log(password);
|
|
return this.http.put(`${this.apiUrl}/membres/reset-password/${email}`, body);
|
|
}
|
|
|
|
creationTeam(team: Team): Observable<any> {
|
|
console.log(team);
|
|
|
|
return this.http.post(`${this.apiUrl}/teams/add`, team);
|
|
}
|
|
|
|
|
|
|
|
addMember(membre: Membre): Observable<any> {
|
|
console.log(membre);
|
|
|
|
return this.http.post(`${this.apiUrl}/tableau-de-bord`, membre);
|
|
}
|
|
|
|
}
|