Changeset bdd6491 for trip-planner-front/src/app/_services/user.service.ts
- Timestamp:
- 12/28/21 08:56:55 (3 years ago)
- Branches:
- master
- Children:
- b738035
- Parents:
- 84d0fbb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trip-planner-front/src/app/_services/user.service.ts
r84d0fbb rbdd6491 8 8 9 9 @Injectable({ 10 10 providedIn: 'root' 11 11 }) 12 export class UserService {12 export class UserService { 13 13 14 15 16 14 headers = new HttpHeaders({ 15 'Content-Type': 'application/json', 16 'Access-Control-Allow-Headers': 'Content-Type', 17 17 18 }); 19 20 constructor(private httpClient: HttpClient){ 18 }); 21 19 22 }20 constructor(private httpClient: HttpClient) { 23 21 24 registerUser(user : UserDto) : Observable<User>{25 let url = "http://localhost:8080/api/users/register"; 26 var reqHeader = new HttpHeaders({'No-Auth' : 'True'});27 return this.httpClient.post<User>(url, user, { headers: reqHeader });28 }29 30 authenticateUser(loginResult : LoginRequest) { 31 let url = "http://localhost:8080/api/users/login";32 var reqHeader = new HttpHeaders({'Content-Type': 'application/json'});33 34 35 36 37 let tokenStr =userData.token;38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 22 } 23 24 registerUser(user: UserDto): Observable<User> { 25 let url = "http://localhost:8080/api/users/register"; 26 return this.httpClient.post<User>(url, user, { headers: this.headers }); 27 } 28 29 authenticateUser(loginResult: LoginRequest) { 30 let url = "http://localhost:8080/api/users/login"; 31 return this.httpClient.post<any>(url, loginResult) 32 .pipe( 33 map(userData => { 34 sessionStorage.setItem("username", loginResult.username); 35 let tokenStr = userData.token; 36 sessionStorage.setItem("token", tokenStr); 37 return userData; 38 }) 39 ); 40 } 41 42 isUserLoggedIn() { 43 let user = sessionStorage.getItem("username"); 44 let token = sessionStorage.getItem("token"); 45 console.log(user); 46 console.log(token); 47 console.log(!(user === null)); 48 return !(user === null); 49 } 50 53 51 }
Note:
See TracChangeset
for help on using the changeset viewer.