aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/auth/auth.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/shared/auth/auth.service.ts')
-rw-r--r--client/src/app/shared/auth/auth.service.ts20
1 files changed, 13 insertions, 7 deletions
diff --git a/client/src/app/shared/auth/auth.service.ts b/client/src/app/shared/auth/auth.service.ts
index 24d1a4fa2..8eea0c4bf 100644
--- a/client/src/app/shared/auth/auth.service.ts
+++ b/client/src/app/shared/auth/auth.service.ts
@@ -4,7 +4,7 @@ import { Observable } from 'rxjs/Observable';
4import { Subject } from 'rxjs/Subject'; 4import { Subject } from 'rxjs/Subject';
5 5
6import { AuthStatus } from './auth-status.model'; 6import { AuthStatus } from './auth-status.model';
7import { User } from './user.model'; 7import { AuthUser } from './auth-user.model';
8 8
9@Injectable() 9@Injectable()
10export class AuthService { 10export class AuthService {
@@ -17,7 +17,7 @@ export class AuthService {
17 private clientId: string; 17 private clientId: string;
18 private clientSecret: string; 18 private clientSecret: string;
19 private loginChanged: Subject<AuthStatus>; 19 private loginChanged: Subject<AuthStatus>;
20 private user: User = null; 20 private user: AuthUser = null;
21 21
22 constructor(private http: Http) { 22 constructor(private http: Http) {
23 this.loginChanged = new Subject<AuthStatus>(); 23 this.loginChanged = new Subject<AuthStatus>();
@@ -40,7 +40,7 @@ export class AuthService {
40 ); 40 );
41 41
42 // Return null if there is nothing to load 42 // Return null if there is nothing to load
43 this.user = User.load(); 43 this.user = AuthUser.load();
44 } 44 }
45 45
46 getRefreshToken() { 46 getRefreshToken() {
@@ -65,10 +65,16 @@ export class AuthService {
65 return this.user.getTokenType(); 65 return this.user.getTokenType();
66 } 66 }
67 67
68 getUser(): User { 68 getUser(): AuthUser {
69 return this.user; 69 return this.user;
70 } 70 }
71 71
72 isAdmin() {
73 if (this.user === null) return false;
74
75 return this.user.isAdmin();
76 }
77
72 isLoggedIn() { 78 isLoggedIn() {
73 if (this.getAccessToken()) { 79 if (this.getAccessToken()) {
74 return true; 80 return true;
@@ -108,7 +114,7 @@ export class AuthService {
108 logout() { 114 logout() {
109 // TODO: make an HTTP request to revoke the tokens 115 // TODO: make an HTTP request to revoke the tokens
110 this.user = null; 116 this.user = null;
111 User.flush(); 117 AuthUser.flush();
112 118
113 this.setStatus(AuthStatus.LoggedOut); 119 this.setStatus(AuthStatus.LoggedOut);
114 } 120 }
@@ -163,13 +169,13 @@ export class AuthService {
163 const id = obj.id; 169 const id = obj.id;
164 const username = obj.username; 170 const username = obj.username;
165 const role = obj.role; 171 const role = obj.role;
166 const hash_tokens = { 172 const hashTokens = {
167 access_token: obj.access_token, 173 access_token: obj.access_token,
168 token_type: obj.token_type, 174 token_type: obj.token_type,
169 refresh_token: obj.refresh_token 175 refresh_token: obj.refresh_token
170 }; 176 };
171 177
172 this.user = new User(id, username, role, hash_tokens); 178 this.user = new AuthUser({ id, username, role }, hashTokens);
173 this.user.save(); 179 this.user.save();
174 180
175 this.setStatus(AuthStatus.LoggedIn); 181 this.setStatus(AuthStatus.LoggedIn);