-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,52 @@ | ||
import { Injectable } from "@angular/core"; | ||
import { Observable } from "rxjs"; | ||
import { HttpClient } from "@angular/common/http"; | ||
import { environment } from "src/environments/environment"; | ||
import { User } from "../../models/User"; | ||
import { | ||
UserRegistrationInput, | ||
UserLoginInput, | ||
UserLoginOutput, | ||
} from "src/app/interfaces/api-middleware"; | ||
import { Injectable } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { HttpClient } from '@angular/common/http'; | ||
import { environment } from 'src/environments/environment'; | ||
import { User } from '../../models/User'; | ||
import { UserRegistrationInput, UserLoginInput, UserLoginOutput } from 'src/app/interfaces/api-middleware'; | ||
|
||
@Injectable({ | ||
providedIn: "root", | ||
providedIn: 'root', | ||
}) | ||
export class AuthAPIService { | ||
private apiURL = environment.apiUrl; | ||
|
||
constructor(private http: HttpClient) {} | ||
|
||
// User registration | ||
register(user: UserRegistrationInput): Observable<any> { | ||
const url = this.apiURL + "register"; | ||
return this.http.post(url, user); | ||
} | ||
|
||
// Login | ||
login(user: UserLoginInput): Observable<UserLoginOutput> { | ||
const url = this.apiURL + "login"; | ||
return this.http.post<any>(url, user); | ||
} | ||
|
||
logout(): Observable<any> { | ||
const url = this.apiURL + "logout"; | ||
return this.http.post<any>(url, {}); | ||
} | ||
|
||
getCurrentUser(): Observable<UserLoginOutput> { | ||
const url = this.apiURL + "user"; | ||
return this.http.post<any>(url, {}); | ||
} | ||
|
||
deleteUser(user: User): Observable<any> { | ||
const url = this.apiURL + "deleteuser"; | ||
return this.http.post<any>(url, user); | ||
} | ||
private apiURL = environment.apiUrl; | ||
|
||
constructor(private http: HttpClient) {} | ||
|
||
// User registration | ||
public register(user: UserRegistrationInput): Observable<any> { | ||
const url = this.apiURL + 'register'; | ||
return this.http.post(url, user); | ||
} | ||
|
||
// Login | ||
public login(user: UserLoginInput): Observable<UserLoginOutput> { | ||
const url = this.apiURL + 'login'; | ||
return this.http.post<any>(url, user); | ||
} | ||
|
||
public logout(): Observable<any> { | ||
const url = this.apiURL + 'logout'; | ||
return this.http.post<any>(url, {}); | ||
} | ||
|
||
public getCurrentUser(): Observable<UserLoginOutput> { | ||
const url = this.apiURL + 'user'; | ||
return this.http.post<any>(url, {}); | ||
} | ||
|
||
public deleteUser(user: User): Observable<any> { | ||
const url = this.apiURL + 'deleteuser'; | ||
return this.http.post<any>(url, user); | ||
} | ||
|
||
public forgotPassword(email: string): Observable<any> { | ||
const url = this.apiURL + 'forgot-password'; | ||
return this.http.post<any>(url, { email }); | ||
} | ||
|
||
public resetPassword(token: string, email: string, password: string): Observable<any> { | ||
const url = this.apiURL + 'reset-password'; | ||
return this.http.post<any>(url, { token, email, password }); | ||
} | ||
} |