diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-25 17:31:11 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-26 09:11:38 +0200 |
commit | bcd9f81eff05ffd930c5d8175fb907d4d371432a (patch) | |
tree | 071c9bff7135ae968f329623b77a4835e1afcb59 /client/src/app/core/auth | |
parent | d412e80e5f748f92118541a5334c14ebd4a90881 (diff) | |
download | PeerTube-bcd9f81eff05ffd930c5d8175fb907d4d371432a.tar.gz PeerTube-bcd9f81eff05ffd930c5d8175fb907d4d371432a.tar.zst PeerTube-bcd9f81eff05ffd930c5d8175fb907d4d371432a.zip |
Add channels to upload form
Diffstat (limited to 'client/src/app/core/auth')
-rw-r--r-- | client/src/app/core/auth/auth-user.model.ts | 10 | ||||
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 48 |
2 files changed, 37 insertions, 21 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 4155aea19..81bff99a0 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts | |||
@@ -1,6 +1,6 @@ | |||
1 | // Do not use the barrel (dependency loop) | 1 | // Do not use the barrel (dependency loop) |
2 | import { UserRole } from '../../../../../shared/models/users/user-role.type' | 2 | import { UserRole } from '../../../../../shared/models/users/user-role.type' |
3 | import { User } from '../../shared/users/user.model' | 3 | import { User, UserConstructorHash } from '../../shared/users/user.model' |
4 | 4 | ||
5 | export type TokenOptions = { | 5 | export type TokenOptions = { |
6 | accessToken: string | 6 | accessToken: string |
@@ -100,13 +100,7 @@ export class AuthUser extends User { | |||
100 | Tokens.flush() | 100 | Tokens.flush() |
101 | } | 101 | } |
102 | 102 | ||
103 | constructor (userHash: { | 103 | constructor (userHash: UserConstructorHash, hashTokens: TokenOptions) { |
104 | id: number, | ||
105 | username: string, | ||
106 | role: UserRole, | ||
107 | email: string, | ||
108 | displayNSFW: boolean | ||
109 | }, hashTokens: TokenOptions) { | ||
110 | super(userHash) | 104 | super(userHash) |
111 | this.tokens = new Tokens(hashTokens) | 105 | this.tokens = new Tokens(hashTokens) |
112 | } | 106 | } |
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 | ||
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, UserRole, UserRefreshToken } from '../../../../../shared' | 14 | import { |
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) |
16 | import { RestExtractor } from '../../shared/rest' | 22 | import { RestExtractor } from '../../shared/rest' |
17 | import { UserLogin } from '../../../../../shared/models/users/user-login.model' | 23 | import { UserLogin } from '../../../../../shared/models/users/user-login.model' |
18 | import { User } from '../../shared/users/user.model' | 24 | import { User, UserConstructorHash } from '../../shared/users/user.model' |
19 | 25 | ||
20 | interface UserLoginWithUsername extends UserLogin { | 26 | interface 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) |