source: Sources/frontend/src/app/login.service.ts@ cd15236

Last change on this file since cd15236 was 8423429, checked in by AngelNasev <angel.nasev@…>, 17 months ago

Add backend and frontend projects

  • Property mode set to 100644
File size: 1.1 KB
RevLine 
[8423429]1import {Injectable} from '@angular/core';
2import {HttpClient, HttpParams} from "@angular/common/http";
3import {ActiveUserInterface} from "./ActiveUserInterface";
4import {Router} from "@angular/router";
5
6@Injectable({
7 providedIn: 'root'
8})
9export class LoginService {
10
11 url = "http://localhost:8080/api/login"
12 activeUser: ActiveUserInterface | undefined;
13 currentCourse: number | undefined;
14
15 constructor(private http: HttpClient, private router: Router) {
16 }
17
18 loginUser(username: string, password: string) {
19 const params = new HttpParams()
20 .append('username', username)
21 .append('password', password);
22 console.log("params", params)
23 this.http.get<ActiveUserInterface>(this.url, {params:params})
24 .subscribe(resp => {
25 console.log("Response login", resp);
26 this.activeUser = resp;
27 console.log("active user", this.activeUser)
28 if (this.activeUser.userType==="ADMIN")
29 this.router.navigate(['/admin-panel'])
30 else
31 this.router.navigate(['/courses']);
32 })
33 }
34
35 setCurrentCourse(id: number) : void{
36 this.currentCourse = id;
37 console.log("Current course is ", id);
38 }
39}
Note: See TracBrowser for help on using the repository browser.