aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core/auth/auth.service.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core/auth/auth.service.ts')
-rw-r--r--client/src/app/core/auth/auth.service.ts48
1 files changed, 35 insertions, 13 deletions
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts
index 4a8814c4e..9ac9ba7bb 100644
--- a/client/src/app/core/auth/auth.service.ts
+++ b/client/src/app/core/auth/auth.service.ts
@@ -11,11 +11,17 @@ import { NotificationsService } from 'angular2-notifications'
11 11
12import { AuthStatus } from './auth-status.model' 12import { AuthStatus } from './auth-status.model'
13import { AuthUser } from './auth-user.model' 13import { AuthUser } from './auth-user.model'
14import { OAuthClientLocal, UserRole, UserRefreshToken } from '../../../../../shared' 14import {
15 OAuthClientLocal,
16 UserRole,
17 UserRefreshToken,
18 VideoChannel,
19 User as UserServerModel
20} from '../../../../../shared'
15// Do not use the barrel (dependency loop) 21// Do not use the barrel (dependency loop)
16import { RestExtractor } from '../../shared/rest' 22import { RestExtractor } from '../../shared/rest'
17import { UserLogin } from '../../../../../shared/models/users/user-login.model' 23import { UserLogin } from '../../../../../shared/models/users/user-login.model'
18import { User } from '../../shared/users/user.model' 24import { User, UserConstructorHash } from '../../shared/users/user.model'
19 25
20interface UserLoginWithUsername extends UserLogin { 26interface UserLoginWithUsername extends UserLogin {
21 access_token: string 27 access_token: string
@@ -33,6 +39,12 @@ interface UserLoginWithUserInformation extends UserLogin {
33 role: UserRole 39 role: UserRole
34 displayNSFW: boolean 40 displayNSFW: boolean
35 email: string 41 email: string
42 videoQuota: number
43 author: {
44 id: number
45 uuid: string
46 }
47 videoChannels: VideoChannel[]
36} 48}
37 49
38@Injectable() 50@Injectable()
@@ -197,6 +209,8 @@ export class AuthService {
197 res => { 209 res => {
198 this.user.displayNSFW = res.displayNSFW 210 this.user.displayNSFW = res.displayNSFW
199 this.user.role = res.role 211 this.user.role = res.role
212 this.user.videoChannels = res.videoChannels
213 this.user.author = res.author
200 214
201 this.user.save() 215 this.user.save()
202 } 216 }
@@ -207,13 +221,16 @@ export class AuthService {
207 // User is not loaded yet, set manually auth header 221 // User is not loaded yet, set manually auth header
208 const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`) 222 const headers = new HttpHeaders().set('Authorization', `${obj.token_type} ${obj.access_token}`)
209 223
210 return this.http.get<User>(AuthService.BASE_USER_INFORMATION_URL, { headers }) 224 return this.http.get<UserServerModel>(AuthService.BASE_USER_INFORMATION_URL, { headers })
211 .map(res => { 225 .map(res => {
212 const newProperties = { 226 const newProperties = {
213 id: res.id as number, 227 id: res.id,
214 role: res.role as UserRole, 228 role: res.role,
215 displayNSFW: res.displayNSFW as boolean, 229 displayNSFW: res.displayNSFW,
216 email: res.email as string 230 email: res.email,
231 videoQuota: res.videoQuota,
232 author: res.author,
233 videoChannels: res.videoChannels
217 } 234 }
218 235
219 return Object.assign(obj, newProperties) 236 return Object.assign(obj, newProperties)
@@ -222,18 +239,23 @@ export class AuthService {
222 } 239 }
223 240
224 private handleLogin (obj: UserLoginWithUserInformation) { 241 private handleLogin (obj: UserLoginWithUserInformation) {
225 const id = obj.id 242 const hashUser: UserConstructorHash = {
226 const username = obj.username 243 id: obj.id,
227 const role = obj.role 244 username: obj.username,
228 const email = obj.email 245 role: obj.role,
229 const displayNSFW = obj.displayNSFW 246 email: obj.email,
247 displayNSFW: obj.displayNSFW,
248 videoQuota: obj.videoQuota,
249 videoChannels: obj.videoChannels,
250 author: obj.author
251 }
230 const hashTokens = { 252 const hashTokens = {
231 accessToken: obj.access_token, 253 accessToken: obj.access_token,
232 tokenType: obj.token_type, 254 tokenType: obj.token_type,
233 refreshToken: obj.refresh_token 255 refreshToken: obj.refresh_token
234 } 256 }
235 257
236 this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens) 258 this.user = new AuthUser(hashUser, hashTokens)
237 this.user.save() 259 this.user.save()
238 260
239 this.setStatus(AuthStatus.LoggedIn) 261 this.setStatus(AuthStatus.LoggedIn)