diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 10:09:18 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-07-11 10:09:18 +0200 |
commit | 33c4972d5b54155540267f4c9c9ee55c539b8385 (patch) | |
tree | c150d11c0afdeb90c19c4d59297c6829b2d55dd1 /client/src/app/core/auth/auth.service.ts | |
parent | 4771e0008dd26eadbb7eaff64255a6ec914fdadb (diff) | |
download | PeerTube-33c4972d5b54155540267f4c9c9ee55c539b8385.tar.gz PeerTube-33c4972d5b54155540267f4c9c9ee55c539b8385.tar.zst PeerTube-33c4972d5b54155540267f4c9c9ee55c539b8385.zip |
Type webtorrent
Diffstat (limited to 'client/src/app/core/auth/auth.service.ts')
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 34 |
1 files changed, 26 insertions, 8 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index d5aa80512..de9e14b2d 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts | |||
@@ -11,7 +11,7 @@ import { NotificationsService } from 'angular2-notifications' | |||
11 | 11 | ||
12 | import { AuthStatus } from './auth-status.model' | 12 | import { AuthStatus } from './auth-status.model' |
13 | import { AuthUser } from './auth-user.model' | 13 | import { AuthUser } from './auth-user.model' |
14 | import { OAuthClientLocal } from '../../../../../shared' | 14 | import { OAuthClientLocal, UserRole } from '../../../../../shared' |
15 | // Do not use the barrel (dependency loop) | 15 | // Do not use the barrel (dependency loop) |
16 | import { RestExtractor } from '../../shared/rest' | 16 | import { RestExtractor } from '../../shared/rest' |
17 | 17 | ||
@@ -181,7 +181,10 @@ export class AuthService { | |||
181 | 181 | ||
182 | refreshUserInformations () { | 182 | refreshUserInformations () { |
183 | const obj = { | 183 | const obj = { |
184 | access_token: this.user.getAccessToken() | 184 | access_token: this.user.getAccessToken(), |
185 | refresh_token: null, | ||
186 | token_type: this.user.getTokenType(), | ||
187 | username: this.user.username | ||
185 | } | 188 | } |
186 | 189 | ||
187 | this.mergeUserInformations (obj) | 190 | this.mergeUserInformations (obj) |
@@ -195,7 +198,12 @@ export class AuthService { | |||
195 | ) | 198 | ) |
196 | } | 199 | } |
197 | 200 | ||
198 | private mergeUserInformations (obj: { access_token: string }) { | 201 | private mergeUserInformations (obj: { |
202 | access_token: string, | ||
203 | refresh_token: string, | ||
204 | token_type: string, | ||
205 | username: string | ||
206 | }) { | ||
199 | // Do not call authHttp here to avoid circular dependencies headaches | 207 | // Do not call authHttp here to avoid circular dependencies headaches |
200 | 208 | ||
201 | const headers = new Headers() | 209 | const headers = new Headers() |
@@ -205,9 +213,10 @@ export class AuthService { | |||
205 | .map(res => res.json()) | 213 | .map(res => res.json()) |
206 | .map(res => { | 214 | .map(res => { |
207 | const newProperties = { | 215 | const newProperties = { |
208 | id: res.id, | 216 | id: res.id as number, |
209 | role: res.role, | 217 | role: res.role as UserRole, |
210 | displayNSFW: res.displayNSFW | 218 | displayNSFW: res.displayNSFW as boolean, |
219 | email: res.email as string | ||
211 | } | 220 | } |
212 | 221 | ||
213 | return Object.assign(obj, newProperties) | 222 | return Object.assign(obj, newProperties) |
@@ -215,7 +224,16 @@ export class AuthService { | |||
215 | ) | 224 | ) |
216 | } | 225 | } |
217 | 226 | ||
218 | private handleLogin (obj: any) { | 227 | private handleLogin (obj: { |
228 | access_token: string, | ||
229 | refresh_token: string, | ||
230 | token_type: string, | ||
231 | id: number, | ||
232 | username: string, | ||
233 | email: string, | ||
234 | role: UserRole, | ||
235 | displayNSFW: boolean | ||
236 | }) { | ||
219 | const id = obj.id | 237 | const id = obj.id |
220 | const username = obj.username | 238 | const username = obj.username |
221 | const role = obj.role | 239 | const role = obj.role |
@@ -233,7 +251,7 @@ export class AuthService { | |||
233 | this.setStatus(AuthStatus.LoggedIn) | 251 | this.setStatus(AuthStatus.LoggedIn) |
234 | } | 252 | } |
235 | 253 | ||
236 | private handleRefreshToken (obj: any) { | 254 | private handleRefreshToken (obj: { access_token: string, refresh_token: string }) { |
237 | this.user.refreshTokens(obj.access_token, obj.refresh_token) | 255 | this.user.refreshTokens(obj.access_token, obj.refresh_token) |
238 | this.user.save() | 256 | this.user.save() |
239 | } | 257 | } |