Revision 51275
Added by Myrto Koukouli over 6 years ago
authentication.service.ts | ||
---|---|---|
4 | 4 |
import { deleteCookie, getCookie } from '../domain/utils'; |
5 | 5 |
import { Http } from '@angular/http'; |
6 | 6 |
import { User } from '../domain/typeScriptClasses'; |
7 |
import {CookieService} from "angular2-cookie/core"; |
|
8 | 7 |
|
9 | 8 |
@Injectable() |
10 | 9 |
export class AuthenticationService { |
11 | 10 |
|
12 | 11 |
constructor(private route: ActivatedRoute, |
13 | 12 |
private router: Router, |
14 |
private http: Http, |
|
15 |
private _cookie: CookieService) {} |
|
13 |
private http: Http) {} |
|
16 | 14 |
|
17 | 15 |
private loginUrl : string = loginUrl; |
18 | 16 |
private apiUrl : string = apiUrl; |
... | ... | |
34 | 32 |
window.location.href = this.loginUrl; |
35 | 33 |
} |
36 | 34 |
|
37 |
login(user: User){ |
|
38 |
localStorage.setItem('user', JSON.stringify(user)); |
|
39 |
this.isLoggedIn = true; |
|
40 |
this.userEmail = localStorage.getItem('email'); |
|
41 |
this.userFullName = localStorage.getItem('name'); |
|
42 |
this.userRole = localStorage.getItem('role'); |
|
43 |
} |
|
44 |
|
|
45 |
logout(){ |
|
35 |
public logout(){ |
|
46 | 36 |
deleteCookie('currentUser'); |
47 | 37 |
sessionStorage.removeItem('name'); |
48 | 38 |
sessionStorage.removeItem('email'); |
49 | 39 |
sessionStorage.removeItem('role'); |
40 |
this.isLoggedIn = false; |
|
50 | 41 |
this.router.navigate(['/home']); |
42 |
window.location.replace(`https://aai.openminted.eu/proxy/saml2/idp/SingleLogoutService.php?ReturnTo=${this.router.url}`); |
|
51 | 43 |
} |
52 | 44 |
|
53 | 45 |
public tryLogin() { |
54 |
|
|
55 | 46 |
if(getCookie('currentUser')) { |
56 | 47 |
console.log(`I got the cookie!`); |
57 | 48 |
this.http.get(this.apiUrl + '/user/login',{ withCredentials: true }).subscribe( |
... | ... | |
87 | 78 |
} |
88 | 79 |
} |
89 | 80 |
|
90 |
public getIsUserLoggedIn() {
|
|
91 |
return this.isLoggedIn;
|
|
92 |
}
|
|
81 |
public getIsUserLoggedIn() { |
|
82 |
return this.isLoggedIn; |
|
83 |
} |
|
93 | 84 |
|
94 |
public getUserName() {
|
|
95 |
if (this.isLoggedIn)
|
|
96 |
return sessionStorage.getItem('name');
|
|
97 |
}
|
|
85 |
public getUserName() { |
|
86 |
if (this.isLoggedIn) |
|
87 |
return sessionStorage.getItem('name'); |
|
88 |
} |
|
98 | 89 |
|
99 |
public getUserEmail() {
|
|
100 |
if (this.isLoggedIn)
|
|
101 |
return sessionStorage.getItem('email');
|
|
102 |
}
|
|
90 |
public getUserEmail() { |
|
91 |
if (this.isLoggedIn) |
|
92 |
return sessionStorage.getItem('email'); |
|
93 |
} |
|
103 | 94 |
|
104 |
public getUserRole() {
|
|
105 |
if (this.isLoggedIn)
|
|
106 |
return sessionStorage.getItem('role');
|
|
107 |
}
|
|
95 |
public getUserRole() { |
|
96 |
if (this.isLoggedIn) |
|
97 |
return sessionStorage.getItem('role'); |
|
98 |
} |
|
108 | 99 |
|
109 | 100 |
} |
Also available in: Unified diff
fixed login