diff options
Diffstat (limited to 'client/src/app/core')
-rw-r--r-- | client/src/app/core/auth/auth-user.model.ts | 63 | ||||
-rw-r--r-- | client/src/app/core/auth/auth.service.ts | 2 | ||||
-rw-r--r-- | client/src/app/core/rest/rest-table.ts | 2 | ||||
-rw-r--r-- | client/src/app/core/server/server.service.ts | 3 | ||||
-rw-r--r-- | client/src/app/core/users/user.model.ts | 17 | ||||
-rw-r--r-- | client/src/app/core/wrappers/storage.service.ts | 2 |
6 files changed, 9 insertions, 80 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts index 88b730938..ee61ff881 100644 --- a/client/src/app/core/auth/auth-user.model.ts +++ b/client/src/app/core/auth/auth-user.model.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Observable, of } from 'rxjs' | 1 | import { Observable, of } from 'rxjs' |
2 | import { map } from 'rxjs/operators' | 2 | import { map } from 'rxjs/operators' |
3 | import { User } from '@app/core/users/user.model' | 3 | import { User } from '@app/core/users/user.model' |
4 | import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' | 4 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
5 | import { | 5 | import { |
6 | hasUserRight, | 6 | hasUserRight, |
7 | MyUser as ServerMyUserModel, | 7 | MyUser as ServerMyUserModel, |
@@ -12,66 +12,7 @@ import { | |||
12 | UserRole, | 12 | UserRole, |
13 | UserVideoQuota | 13 | UserVideoQuota |
14 | } from '@shared/models' | 14 | } from '@shared/models' |
15 | 15 | import { TokenOptions, Tokens } from '../../../root-helpers/pure-auth-user.model' | |
16 | export type TokenOptions = { | ||
17 | accessToken: string | ||
18 | refreshToken: string | ||
19 | tokenType: string | ||
20 | } | ||
21 | |||
22 | // Private class only used by User | ||
23 | class Tokens { | ||
24 | private static KEYS = { | ||
25 | ACCESS_TOKEN: 'access_token', | ||
26 | REFRESH_TOKEN: 'refresh_token', | ||
27 | TOKEN_TYPE: 'token_type' | ||
28 | } | ||
29 | |||
30 | accessToken: string | ||
31 | refreshToken: string | ||
32 | tokenType: string | ||
33 | |||
34 | static load () { | ||
35 | const accessTokenLocalStorage = peertubeLocalStorage.getItem(this.KEYS.ACCESS_TOKEN) | ||
36 | const refreshTokenLocalStorage = peertubeLocalStorage.getItem(this.KEYS.REFRESH_TOKEN) | ||
37 | const tokenTypeLocalStorage = peertubeLocalStorage.getItem(this.KEYS.TOKEN_TYPE) | ||
38 | |||
39 | if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) { | ||
40 | return new Tokens({ | ||
41 | accessToken: accessTokenLocalStorage, | ||
42 | refreshToken: refreshTokenLocalStorage, | ||
43 | tokenType: tokenTypeLocalStorage | ||
44 | }) | ||
45 | } | ||
46 | |||
47 | return null | ||
48 | } | ||
49 | |||
50 | static flush () { | ||
51 | peertubeLocalStorage.removeItem(this.KEYS.ACCESS_TOKEN) | ||
52 | peertubeLocalStorage.removeItem(this.KEYS.REFRESH_TOKEN) | ||
53 | peertubeLocalStorage.removeItem(this.KEYS.TOKEN_TYPE) | ||
54 | } | ||
55 | |||
56 | constructor (hash?: TokenOptions) { | ||
57 | if (hash) { | ||
58 | this.accessToken = hash.accessToken | ||
59 | this.refreshToken = hash.refreshToken | ||
60 | |||
61 | if (hash.tokenType === 'bearer') { | ||
62 | this.tokenType = 'Bearer' | ||
63 | } else { | ||
64 | this.tokenType = hash.tokenType | ||
65 | } | ||
66 | } | ||
67 | } | ||
68 | |||
69 | save () { | ||
70 | peertubeLocalStorage.setItem(Tokens.KEYS.ACCESS_TOKEN, this.accessToken) | ||
71 | peertubeLocalStorage.setItem(Tokens.KEYS.REFRESH_TOKEN, this.refreshToken) | ||
72 | peertubeLocalStorage.setItem(Tokens.KEYS.TOKEN_TYPE, this.tokenType) | ||
73 | } | ||
74 | } | ||
75 | 16 | ||
76 | export class AuthUser extends User implements ServerMyUserModel { | 17 | export class AuthUser extends User implements ServerMyUserModel { |
77 | tokens: Tokens | 18 | tokens: Tokens |
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts index 94262b9aa..d3dc48267 100644 --- a/client/src/app/core/auth/auth.service.ts +++ b/client/src/app/core/auth/auth.service.ts | |||
@@ -5,7 +5,7 @@ import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http' | |||
5 | import { Injectable } from '@angular/core' | 5 | import { Injectable } from '@angular/core' |
6 | import { Router } from '@angular/router' | 6 | import { Router } from '@angular/router' |
7 | import { Notifier } from '@app/core/notification/notifier.service' | 7 | import { Notifier } from '@app/core/notification/notifier.service' |
8 | import { objectToUrlEncoded, peertubeLocalStorage } from '@app/helpers' | 8 | import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index' |
9 | import { I18n } from '@ngx-translate/i18n-polyfill' | 9 | import { I18n } from '@ngx-translate/i18n-polyfill' |
10 | import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' | 10 | import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' |
11 | import { environment } from '../../../environments/environment' | 11 | import { environment } from '../../../environments/environment' |
diff --git a/client/src/app/core/rest/rest-table.ts b/client/src/app/core/rest/rest-table.ts index e6328eddc..7e7e6f4f7 100644 --- a/client/src/app/core/rest/rest-table.ts +++ b/client/src/app/core/rest/rest-table.ts | |||
@@ -1,4 +1,4 @@ | |||
1 | import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' | 1 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' |
2 | import { LazyLoadEvent, SortMeta } from 'primeng/api' | 2 | import { LazyLoadEvent, SortMeta } from 'primeng/api' |
3 | import { RestPagination } from './rest-pagination' | 3 | import { RestPagination } from './rest-pagination' |
4 | import { Subject } from 'rxjs' | 4 | import { Subject } from 'rxjs' |
diff --git a/client/src/app/core/server/server.service.ts b/client/src/app/core/server/server.service.ts index 32a135203..c69e0919a 100644 --- a/client/src/app/core/server/server.service.ts +++ b/client/src/app/core/server/server.service.ts | |||
@@ -2,7 +2,8 @@ import { Observable, of, Subject } from 'rxjs' | |||
2 | import { first, map, share, shareReplay, switchMap, tap } from 'rxjs/operators' | 2 | import { first, map, share, shareReplay, switchMap, tap } from 'rxjs/operators' |
3 | import { HttpClient } from '@angular/common/http' | 3 | import { HttpClient } from '@angular/common/http' |
4 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' | 4 | import { Inject, Injectable, LOCALE_ID } from '@angular/core' |
5 | import { getDevLocale, isOnDevLocale, peertubeLocalStorage, sortBy } from '@app/helpers' | 5 | import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers' |
6 | import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage' | ||
6 | import { | 7 | import { |
7 | getCompleteLocale, | 8 | getCompleteLocale, |
8 | isDefaultLocale, | 9 | isDefaultLocale, |
diff --git a/client/src/app/core/users/user.model.ts b/client/src/app/core/users/user.model.ts index 4256f370b..a94b35c46 100644 --- a/client/src/app/core/users/user.model.ts +++ b/client/src/app/core/users/user.model.ts | |||
@@ -10,23 +10,10 @@ import { | |||
10 | UserRole, | 10 | UserRole, |
11 | VideoChannel | 11 | VideoChannel |
12 | } from '@shared/models' | 12 | } from '@shared/models' |
13 | import { UserKeys } from '@root-helpers/user-keys' | ||
13 | 14 | ||
14 | export class User implements UserServerModel { | 15 | export class User implements UserServerModel { |
15 | static KEYS = { | 16 | static KEYS = UserKeys |
16 | ID: 'id', | ||
17 | ROLE: 'role', | ||
18 | EMAIL: 'email', | ||
19 | VIDEOS_HISTORY_ENABLED: 'videos-history-enabled', | ||
20 | USERNAME: 'username', | ||
21 | NSFW_POLICY: 'nsfw_policy', | ||
22 | WEBTORRENT_ENABLED: 'peertube-videojs-' + 'webtorrent_enabled', | ||
23 | AUTO_PLAY_VIDEO: 'auto_play_video', | ||
24 | SESSION_STORAGE_AUTO_PLAY_NEXT_VIDEO: 'auto_play_next_video', | ||
25 | AUTO_PLAY_VIDEO_PLAYLIST: 'auto_play_video_playlist', | ||
26 | THEME: 'theme', | ||
27 | LAST_ACTIVE_THEME: 'last_active_theme', | ||
28 | VIDEO_LANGUAGES: 'video_languages' | ||
29 | } | ||
30 | 17 | ||
31 | id: number | 18 | id: number |
32 | username: string | 19 | username: string |
diff --git a/client/src/app/core/wrappers/storage.service.ts b/client/src/app/core/wrappers/storage.service.ts index 9a60b9785..ad3aca6b8 100644 --- a/client/src/app/core/wrappers/storage.service.ts +++ b/client/src/app/core/wrappers/storage.service.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Observable, Subject } from 'rxjs' | 1 | import { Observable, Subject } from 'rxjs' |
2 | import { filter } from 'rxjs/operators' | 2 | import { filter } from 'rxjs/operators' |
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { peertubeLocalStorage, peertubeSessionStorage } from '@app/helpers' | 4 | import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage' |
5 | 5 | ||
6 | abstract class StorageService { | 6 | abstract class StorageService { |
7 | protected instance: Storage | 7 | protected instance: Storage |