From 33c4972d5b54155540267f4c9c9ee55c539b8385 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 11 Jul 2017 10:09:18 +0200 Subject: Type webtorrent --- client/src/app/core/auth/auth-user.model.ts | 2 ++ client/src/app/core/auth/auth.service.ts | 34 ++++++++++++++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) (limited to 'client/src/app/core') diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 9cb201907..4155aea19 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts @@ -96,6 +96,7 @@ export class AuthUser extends User { localStorage.removeItem(this.KEYS.ID) localStorage.removeItem(this.KEYS.ROLE) localStorage.removeItem(this.KEYS.DISPLAY_NSFW) + localStorage.removeItem(this.KEYS.EMAIL) Tokens.flush() } @@ -130,6 +131,7 @@ export class AuthUser extends User { save () { localStorage.setItem(AuthUser.KEYS.ID, this.id.toString()) localStorage.setItem(AuthUser.KEYS.USERNAME, this.username) + localStorage.setItem(AuthUser.KEYS.EMAIL, this.email) localStorage.setItem(AuthUser.KEYS.ROLE, this.role) localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW)) this.tokens.save() 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' import { AuthStatus } from './auth-status.model' import { AuthUser } from './auth-user.model' -import { OAuthClientLocal } from '../../../../../shared' +import { OAuthClientLocal, UserRole } from '../../../../../shared' // Do not use the barrel (dependency loop) import { RestExtractor } from '../../shared/rest' @@ -181,7 +181,10 @@ export class AuthService { refreshUserInformations () { const obj = { - access_token: this.user.getAccessToken() + access_token: this.user.getAccessToken(), + refresh_token: null, + token_type: this.user.getTokenType(), + username: this.user.username } this.mergeUserInformations (obj) @@ -195,7 +198,12 @@ export class AuthService { ) } - private mergeUserInformations (obj: { access_token: string }) { + private mergeUserInformations (obj: { + access_token: string, + refresh_token: string, + token_type: string, + username: string + }) { // Do not call authHttp here to avoid circular dependencies headaches const headers = new Headers() @@ -205,9 +213,10 @@ export class AuthService { .map(res => res.json()) .map(res => { const newProperties = { - id: res.id, - role: res.role, - displayNSFW: res.displayNSFW + id: res.id as number, + role: res.role as UserRole, + displayNSFW: res.displayNSFW as boolean, + email: res.email as string } return Object.assign(obj, newProperties) @@ -215,7 +224,16 @@ export class AuthService { ) } - private handleLogin (obj: any) { + private handleLogin (obj: { + access_token: string, + refresh_token: string, + token_type: string, + id: number, + username: string, + email: string, + role: UserRole, + displayNSFW: boolean + }) { const id = obj.id const username = obj.username const role = obj.role @@ -233,7 +251,7 @@ export class AuthService { this.setStatus(AuthStatus.LoggedIn) } - private handleRefreshToken (obj: any) { + private handleRefreshToken (obj: { access_token: string, refresh_token: string }) { this.user.refreshTokens(obj.access_token, obj.refresh_token) this.user.save() } -- cgit v1.2.3