aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/auth/auth-user.model.ts63
-rw-r--r--client/src/app/core/auth/auth.service.ts2
-rw-r--r--client/src/app/core/rest/rest-table.ts2
-rw-r--r--client/src/app/core/server/server.service.ts3
-rw-r--r--client/src/app/core/users/user.model.ts17
-rw-r--r--client/src/app/core/wrappers/storage.service.ts2
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 @@
1import { Observable, of } from 'rxjs' 1import { Observable, of } from 'rxjs'
2import { map } from 'rxjs/operators' 2import { map } from 'rxjs/operators'
3import { User } from '@app/core/users/user.model' 3import { User } from '@app/core/users/user.model'
4import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' 4import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
5import { 5import {
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 15import { TokenOptions, Tokens } from '../../../root-helpers/pure-auth-user.model'
16export type TokenOptions = {
17 accessToken: string
18 refreshToken: string
19 tokenType: string
20}
21
22// Private class only used by User
23class 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
76export class AuthUser extends User implements ServerMyUserModel { 17export 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'
5import { Injectable } from '@angular/core' 5import { Injectable } from '@angular/core'
6import { Router } from '@angular/router' 6import { Router } from '@angular/router'
7import { Notifier } from '@app/core/notification/notifier.service' 7import { Notifier } from '@app/core/notification/notifier.service'
8import { objectToUrlEncoded, peertubeLocalStorage } from '@app/helpers' 8import { objectToUrlEncoded, peertubeLocalStorage } from '@root-helpers/index'
9import { I18n } from '@ngx-translate/i18n-polyfill' 9import { I18n } from '@ngx-translate/i18n-polyfill'
10import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models' 10import { MyUser as UserServerModel, OAuthClientLocal, User, UserLogin, UserRefreshToken } from '@shared/models'
11import { environment } from '../../../environments/environment' 11import { 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 @@
1import { peertubeLocalStorage } from '@app/helpers/peertube-web-storage' 1import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
2import { LazyLoadEvent, SortMeta } from 'primeng/api' 2import { LazyLoadEvent, SortMeta } from 'primeng/api'
3import { RestPagination } from './rest-pagination' 3import { RestPagination } from './rest-pagination'
4import { Subject } from 'rxjs' 4import { 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'
2import { first, map, share, shareReplay, switchMap, tap } from 'rxjs/operators' 2import { first, map, share, shareReplay, switchMap, tap } from 'rxjs/operators'
3import { HttpClient } from '@angular/common/http' 3import { HttpClient } from '@angular/common/http'
4import { Inject, Injectable, LOCALE_ID } from '@angular/core' 4import { Inject, Injectable, LOCALE_ID } from '@angular/core'
5import { getDevLocale, isOnDevLocale, peertubeLocalStorage, sortBy } from '@app/helpers' 5import { getDevLocale, isOnDevLocale, sortBy } from '@app/helpers'
6import { peertubeLocalStorage } from '@root-helpers/peertube-web-storage'
6import { 7import {
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'
13import { UserKeys } from '@root-helpers/user-keys'
13 14
14export class User implements UserServerModel { 15export 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 @@
1import { Observable, Subject } from 'rxjs' 1import { Observable, Subject } from 'rxjs'
2import { filter } from 'rxjs/operators' 2import { filter } from 'rxjs/operators'
3import { Injectable } from '@angular/core' 3import { Injectable } from '@angular/core'
4import { peertubeLocalStorage, peertubeSessionStorage } from '@app/helpers' 4import { peertubeLocalStorage, peertubeSessionStorage } from '@root-helpers/peertube-web-storage'
5 5
6abstract class StorageService { 6abstract class StorageService {
7 protected instance: Storage 7 protected instance: Storage