aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
commitdf98563e2104b82b119c00a3cd83cd0dc1242d25 (patch)
treea9720bf01bac9ad5646bd3d3c9bc7653617afdad /client/src/app/core
parent46757b477c1adb5f98060d15998a3852e18902a6 (diff)
downloadPeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.gz
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.zst
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.zip
Use typescript standard and lint all files
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/auth/auth-user.model.ts180
-rw-r--r--client/src/app/core/auth/auth.service.ts236
-rw-r--r--client/src/app/core/auth/index.ts4
-rw-r--r--client/src/app/core/config/config.service.ts24
-rw-r--r--client/src/app/core/config/index.ts2
-rw-r--r--client/src/app/core/confirm/confirm.component.ts48
-rw-r--r--client/src/app/core/confirm/confirm.service.ts16
-rw-r--r--client/src/app/core/confirm/index.ts4
-rw-r--r--client/src/app/core/core.module.ts26
-rw-r--r--client/src/app/core/index.ts8
-rw-r--r--client/src/app/core/menu/index.ts4
-rw-r--r--client/src/app/core/menu/menu-admin.component.ts2
-rw-r--r--client/src/app/core/menu/menu.component.ts40
-rw-r--r--client/src/app/core/module-import-guard.ts4
14 files changed, 302 insertions, 296 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts
index 1a31a7834..65c37bcfa 100644
--- a/client/src/app/core/auth/auth-user.model.ts
+++ b/client/src/app/core/auth/auth-user.model.ts
@@ -1,6 +1,66 @@
1// Do not use the barrel (dependency loop) 1// Do not use the barrel (dependency loop)
2import { UserRole } from '../../../../../shared/models/user.model' 2import { UserRole } from '../../../../../shared/models/user.model'
3import { User } from '../../shared/users/user.model'; 3import { User } from '../../shared/users/user.model'
4
5export type TokenOptions = {
6 accessToken: string
7 refreshToken: string
8 tokenType: string
9}
10
11// Private class only used by User
12class Tokens {
13 private static KEYS = {
14 ACCESS_TOKEN: 'access_token',
15 REFRESH_TOKEN: 'refresh_token',
16 TOKEN_TYPE: 'token_type'
17 }
18
19 accessToken: string
20 refreshToken: string
21 tokenType: string
22
23 static load () {
24 const accessTokenLocalStorage = localStorage.getItem(this.KEYS.ACCESS_TOKEN)
25 const refreshTokenLocalStorage = localStorage.getItem(this.KEYS.REFRESH_TOKEN)
26 const tokenTypeLocalStorage = localStorage.getItem(this.KEYS.TOKEN_TYPE)
27
28 if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) {
29 return new Tokens({
30 accessToken: accessTokenLocalStorage,
31 refreshToken: refreshTokenLocalStorage,
32 tokenType: tokenTypeLocalStorage
33 })
34 }
35
36 return null
37 }
38
39 static flush () {
40 localStorage.removeItem(this.KEYS.ACCESS_TOKEN)
41 localStorage.removeItem(this.KEYS.REFRESH_TOKEN)
42 localStorage.removeItem(this.KEYS.TOKEN_TYPE)
43 }
44
45 constructor (hash?: TokenOptions) {
46 if (hash) {
47 this.accessToken = hash.accessToken
48 this.refreshToken = hash.refreshToken
49
50 if (hash.tokenType === 'bearer') {
51 this.tokenType = 'Bearer'
52 } else {
53 this.tokenType = hash.tokenType
54 }
55 }
56 }
57
58 save () {
59 localStorage.setItem(Tokens.KEYS.ACCESS_TOKEN, this.accessToken)
60 localStorage.setItem(Tokens.KEYS.REFRESH_TOKEN, this.refreshToken)
61 localStorage.setItem(Tokens.KEYS.TOKEN_TYPE, this.tokenType)
62 }
63}
4 64
5export class AuthUser extends User { 65export class AuthUser extends User {
6 private static KEYS = { 66 private static KEYS = {
@@ -9,123 +69,69 @@ export class AuthUser extends User {
9 EMAIL: 'email', 69 EMAIL: 'email',
10 USERNAME: 'username', 70 USERNAME: 'username',
11 DISPLAY_NSFW: 'display_nsfw' 71 DISPLAY_NSFW: 'display_nsfw'
12 }; 72 }
13 73
14 tokens: Tokens; 74 tokens: Tokens
15 75
16 static load() { 76 static load () {
17 const usernameLocalStorage = localStorage.getItem(this.KEYS.USERNAME); 77 const usernameLocalStorage = localStorage.getItem(this.KEYS.USERNAME)
18 if (usernameLocalStorage) { 78 if (usernameLocalStorage) {
19 return new AuthUser( 79 return new AuthUser(
20 { 80 {
21 id: parseInt(localStorage.getItem(this.KEYS.ID)), 81 id: parseInt(localStorage.getItem(this.KEYS.ID), 10),
22 username: localStorage.getItem(this.KEYS.USERNAME), 82 username: localStorage.getItem(this.KEYS.USERNAME),
23 email: localStorage.getItem(this.KEYS.EMAIL), 83 email: localStorage.getItem(this.KEYS.EMAIL),
24 role: localStorage.getItem(this.KEYS.ROLE) as UserRole, 84 role: localStorage.getItem(this.KEYS.ROLE) as UserRole,
25 displayNSFW: localStorage.getItem(this.KEYS.DISPLAY_NSFW) === 'true' 85 displayNSFW: localStorage.getItem(this.KEYS.DISPLAY_NSFW) === 'true'
26 }, 86 },
27 Tokens.load() 87 Tokens.load()
28 ); 88 )
29 } 89 }
30 90
31 return null; 91 return null
32 } 92 }
33 93
34 static flush() { 94 static flush () {
35 localStorage.removeItem(this.KEYS.USERNAME); 95 localStorage.removeItem(this.KEYS.USERNAME)
36 localStorage.removeItem(this.KEYS.ID); 96 localStorage.removeItem(this.KEYS.ID)
37 localStorage.removeItem(this.KEYS.ROLE); 97 localStorage.removeItem(this.KEYS.ROLE)
38 localStorage.removeItem(this.KEYS.DISPLAY_NSFW); 98 localStorage.removeItem(this.KEYS.DISPLAY_NSFW)
39 Tokens.flush(); 99 Tokens.flush()
40 } 100 }
41 101
42 constructor(userHash: { 102 constructor (userHash: {
43 id: number, 103 id: number,
44 username: string, 104 username: string,
45 role: UserRole, 105 role: UserRole,
46 email: string, 106 email: string,
47 displayNSFW: boolean 107 displayNSFW: boolean
48 }, hashTokens: any) { 108 }, hashTokens: TokenOptions) {
49 super(userHash); 109 super(userHash)
50 this.tokens = new Tokens(hashTokens); 110 this.tokens = new Tokens(hashTokens)
51 }
52
53 getAccessToken() {
54 return this.tokens.access_token;
55 }
56
57 getRefreshToken() {
58 return this.tokens.refresh_token;
59 }
60
61 getTokenType() {
62 return this.tokens.token_type;
63 }
64
65 refreshTokens(access_token: string, refresh_token: string) {
66 this.tokens.access_token = access_token;
67 this.tokens.refresh_token = refresh_token;
68 } 111 }
69 112
70 save() { 113 getAccessToken () {
71 localStorage.setItem(AuthUser.KEYS.ID, this.id.toString()); 114 return this.tokens.accessToken
72 localStorage.setItem(AuthUser.KEYS.USERNAME, this.username);
73 localStorage.setItem(AuthUser.KEYS.ROLE, this.role);
74 localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW));
75 this.tokens.save();
76 } 115 }
77}
78
79// Private class only used by User
80class Tokens {
81 private static KEYS = {
82 ACCESS_TOKEN: 'access_token',
83 REFRESH_TOKEN: 'refresh_token',
84 TOKEN_TYPE: 'token_type',
85 };
86
87 access_token: string;
88 refresh_token: string;
89 token_type: string;
90
91 static load() {
92 const accessTokenLocalStorage = localStorage.getItem(this.KEYS.ACCESS_TOKEN);
93 const refreshTokenLocalStorage = localStorage.getItem(this.KEYS.REFRESH_TOKEN);
94 const tokenTypeLocalStorage = localStorage.getItem(this.KEYS.TOKEN_TYPE);
95
96 if (accessTokenLocalStorage && refreshTokenLocalStorage && tokenTypeLocalStorage) {
97 return new Tokens({
98 access_token: accessTokenLocalStorage,
99 refresh_token: refreshTokenLocalStorage,
100 token_type: tokenTypeLocalStorage
101 });
102 }
103 116
104 return null; 117 getRefreshToken () {
118 return this.tokens.refreshToken
105 } 119 }
106 120
107 static flush() { 121 getTokenType () {
108 localStorage.removeItem(this.KEYS.ACCESS_TOKEN); 122 return this.tokens.tokenType
109 localStorage.removeItem(this.KEYS.REFRESH_TOKEN);
110 localStorage.removeItem(this.KEYS.TOKEN_TYPE);
111 } 123 }
112 124
113 constructor(hash?: any) { 125 refreshTokens (accessToken: string, refreshToken: string) {
114 if (hash) { 126 this.tokens.accessToken = accessToken
115 this.access_token = hash.access_token; 127 this.tokens.refreshToken = refreshToken
116 this.refresh_token = hash.refresh_token;
117
118 if (hash.token_type === 'bearer') {
119 this.token_type = 'Bearer';
120 } else {
121 this.token_type = hash.token_type;
122 }
123 }
124 } 128 }
125 129
126 save() { 130 save () {
127 localStorage.setItem('access_token', this.access_token); 131 localStorage.setItem(AuthUser.KEYS.ID, this.id.toString())
128 localStorage.setItem('refresh_token', this.refresh_token); 132 localStorage.setItem(AuthUser.KEYS.USERNAME, this.username)
129 localStorage.setItem('token_type', this.token_type); 133 localStorage.setItem(AuthUser.KEYS.ROLE, this.role)
134 localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW))
135 this.tokens.save()
130 } 136 }
131} 137}
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts
index 4c75df1ca..32f7a5503 100644
--- a/client/src/app/core/auth/auth.service.ts
+++ b/client/src/app/core/auth/auth.service.ts
@@ -1,40 +1,40 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Headers, Http, Response, URLSearchParams } from '@angular/http'; 2import { Headers, Http, Response, URLSearchParams } from '@angular/http'
3import { Router } from '@angular/router'; 3import { Router } from '@angular/router'
4import { Observable } from 'rxjs/Observable'; 4import { Observable } from 'rxjs/Observable'
5import { Subject } from 'rxjs/Subject'; 5import { Subject } from 'rxjs/Subject'
6import 'rxjs/add/operator/map'; 6import 'rxjs/add/operator/map'
7import 'rxjs/add/operator/mergeMap'; 7import 'rxjs/add/operator/mergeMap'
8import 'rxjs/add/observable/throw'; 8import 'rxjs/add/observable/throw'
9 9
10import { NotificationsService } from 'angular2-notifications'; 10import { 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'
14// Do not use the barrel (dependency loop) 14// Do not use the barrel (dependency loop)
15import { RestExtractor } from '../../shared/rest'; 15import { RestExtractor } from '../../shared/rest'
16 16
17@Injectable() 17@Injectable()
18export class AuthService { 18export class AuthService {
19 private static BASE_CLIENT_URL = API_URL + '/api/v1/clients/local'; 19 private static BASE_CLIENT_URL = API_URL + '/api/v1/clients/local'
20 private static BASE_TOKEN_URL = API_URL + '/api/v1/users/token'; 20 private static BASE_TOKEN_URL = API_URL + '/api/v1/users/token'
21 private static BASE_USER_INFORMATIONS_URL = API_URL + '/api/v1/users/me'; 21 private static BASE_USER_INFORMATIONS_URL = API_URL + '/api/v1/users/me'
22 22
23 loginChangedSource: Observable<AuthStatus>; 23 loginChangedSource: Observable<AuthStatus>
24 24
25 private clientId: string; 25 private clientId: string
26 private clientSecret: string; 26 private clientSecret: string
27 private loginChanged: Subject<AuthStatus>; 27 private loginChanged: Subject<AuthStatus>
28 private user: AuthUser = null; 28 private user: AuthUser = null
29 29
30 constructor( 30 constructor (
31 private http: Http, 31 private http: Http,
32 private notificationsService: NotificationsService, 32 private notificationsService: NotificationsService,
33 private restExtractor: RestExtractor, 33 private restExtractor: RestExtractor,
34 private router: Router 34 private router: Router
35 ) { 35 ) {
36 this.loginChanged = new Subject<AuthStatus>(); 36 this.loginChanged = new Subject<AuthStatus>()
37 this.loginChangedSource = this.loginChanged.asObservable(); 37 this.loginChangedSource = this.loginChanged.asObservable()
38 38
39 // Fetch the client_id/client_secret 39 // Fetch the client_id/client_secret
40 // FIXME: save in local storage? 40 // FIXME: save in local storage?
@@ -43,120 +43,120 @@ export class AuthService {
43 .catch((res) => this.restExtractor.handleError(res)) 43 .catch((res) => this.restExtractor.handleError(res))
44 .subscribe( 44 .subscribe(
45 result => { 45 result => {
46 this.clientId = result.client_id; 46 this.clientId = result.client_id
47 this.clientSecret = result.client_secret; 47 this.clientSecret = result.client_secret
48 console.log('Client credentials loaded.'); 48 console.log('Client credentials loaded.')
49 }, 49 },
50 50
51 error => { 51 error => {
52 let errorMessage = `Cannot retrieve OAuth Client credentials: ${error.text}. \n`; 52 let errorMessage = `Cannot retrieve OAuth Client credentials: ${error.text}. \n`
53 errorMessage += 'Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.'; 53 errorMessage += 'Ensure you have correctly configured PeerTube (config/ directory), in particular the "webserver" section.'
54 54
55 // We put a bigger timeout 55 // We put a bigger timeout
56 // This is an important message 56 // This is an important message
57 this.notificationsService.error('Error', errorMessage, { timeOut: 7000 }); 57 this.notificationsService.error('Error', errorMessage, { timeOut: 7000 })
58 } 58 }
59 ); 59 )
60 60
61 // Return null if there is nothing to load 61 // Return null if there is nothing to load
62 this.user = AuthUser.load(); 62 this.user = AuthUser.load()
63 } 63 }
64 64
65 getRefreshToken() { 65 getRefreshToken () {
66 if (this.user === null) return null; 66 if (this.user === null) return null
67 67
68 return this.user.getRefreshToken(); 68 return this.user.getRefreshToken()
69 } 69 }
70 70
71 getRequestHeaderValue() { 71 getRequestHeaderValue () {
72 return `${this.getTokenType()} ${this.getAccessToken()}`; 72 return `${this.getTokenType()} ${this.getAccessToken()}`
73 } 73 }
74 74
75 getAccessToken() { 75 getAccessToken () {
76 if (this.user === null) return null; 76 if (this.user === null) return null
77 77
78 return this.user.getAccessToken(); 78 return this.user.getAccessToken()
79 } 79 }
80 80
81 getTokenType() { 81 getTokenType () {
82 if (this.user === null) return null; 82 if (this.user === null) return null
83 83
84 return this.user.getTokenType(); 84 return this.user.getTokenType()
85 } 85 }
86 86
87 getUser(): AuthUser { 87 getUser () {
88 return this.user; 88 return this.user
89 } 89 }
90 90
91 isAdmin() { 91 isAdmin () {
92 if (this.user === null) return false; 92 if (this.user === null) return false
93 93
94 return this.user.isAdmin(); 94 return this.user.isAdmin()
95 } 95 }
96 96
97 isLoggedIn() { 97 isLoggedIn () {
98 if (this.getAccessToken()) { 98 if (this.getAccessToken()) {
99 return true; 99 return true
100 } else { 100 } else {
101 return false; 101 return false
102 } 102 }
103 } 103 }
104 104
105 login(username: string, password: string) { 105 login (username: string, password: string) {
106 let body = new URLSearchParams(); 106 let body = new URLSearchParams()
107 body.set('client_id', this.clientId); 107 body.set('client_id', this.clientId)
108 body.set('client_secret', this.clientSecret); 108 body.set('client_secret', this.clientSecret)
109 body.set('response_type', 'code'); 109 body.set('response_type', 'code')
110 body.set('grant_type', 'password'); 110 body.set('grant_type', 'password')
111 body.set('scope', 'upload'); 111 body.set('scope', 'upload')
112 body.set('username', username); 112 body.set('username', username)
113 body.set('password', password); 113 body.set('password', password)
114 114
115 let headers = new Headers(); 115 let headers = new Headers()
116 headers.append('Content-Type', 'application/x-www-form-urlencoded'); 116 headers.append('Content-Type', 'application/x-www-form-urlencoded')
117 117
118 let options = { 118 let options = {
119 headers: headers 119 headers: headers
120 }; 120 }
121 121
122 return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), options) 122 return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), options)
123 .map(this.restExtractor.extractDataGet) 123 .map(this.restExtractor.extractDataGet)
124 .map(res => { 124 .map(res => {
125 res.username = username; 125 res.username = username
126 return res; 126 return res
127 }) 127 })
128 .flatMap(res => this.mergeUserInformations(res)) 128 .flatMap(res => this.mergeUserInformations(res))
129 .map(res => this.handleLogin(res)) 129 .map(res => this.handleLogin(res))
130 .catch((res) => this.restExtractor.handleError(res)); 130 .catch((res) => this.restExtractor.handleError(res))
131 } 131 }
132 132
133 logout() { 133 logout () {
134 // TODO: make an HTTP request to revoke the tokens 134 // TODO: make an HTTP request to revoke the tokens
135 this.user = null; 135 this.user = null
136 136
137 AuthUser.flush(); 137 AuthUser.flush()
138 138
139 this.setStatus(AuthStatus.LoggedOut); 139 this.setStatus(AuthStatus.LoggedOut)
140 } 140 }
141 141
142 refreshAccessToken() { 142 refreshAccessToken () {
143 console.log('Refreshing token...'); 143 console.log('Refreshing token...')
144 144
145 const refreshToken = this.getRefreshToken(); 145 const refreshToken = this.getRefreshToken()
146 146
147 let body = new URLSearchParams(); 147 let body = new URLSearchParams()
148 body.set('refresh_token', refreshToken); 148 body.set('refresh_token', refreshToken)
149 body.set('client_id', this.clientId); 149 body.set('client_id', this.clientId)
150 body.set('client_secret', this.clientSecret); 150 body.set('client_secret', this.clientSecret)
151 body.set('response_type', 'code'); 151 body.set('response_type', 'code')
152 body.set('grant_type', 'refresh_token'); 152 body.set('grant_type', 'refresh_token')
153 153
154 let headers = new Headers(); 154 let headers = new Headers()
155 headers.append('Content-Type', 'application/x-www-form-urlencoded'); 155 headers.append('Content-Type', 'application/x-www-form-urlencoded')
156 156
157 let options = { 157 let options = {
158 headers: headers 158 headers: headers
159 }; 159 }
160 160
161 return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), options) 161 return this.http.post(AuthService.BASE_TOKEN_URL, body.toString(), options)
162 .map(this.restExtractor.extractDataGet) 162 .map(this.restExtractor.extractDataGet)
@@ -164,41 +164,41 @@ export class AuthService {
164 .catch((res: Response) => { 164 .catch((res: Response) => {
165 // The refresh token is invalid? 165 // The refresh token is invalid?
166 if (res.status === 400 && res.json() && res.json().error === 'invalid_grant') { 166 if (res.status === 400 && res.json() && res.json().error === 'invalid_grant') {
167 console.error('Cannot refresh token -> logout...'); 167 console.error('Cannot refresh token -> logout...')
168 this.logout(); 168 this.logout()
169 this.router.navigate(['/login']); 169 this.router.navigate(['/login'])
170 170
171 return Observable.throw({ 171 return Observable.throw({
172 json: () => '', 172 json: () => '',
173 text: () => 'You need to reconnect.' 173 text: () => 'You need to reconnect.'
174 }); 174 })
175 } 175 }
176 176
177 return this.restExtractor.handleError(res); 177 return this.restExtractor.handleError(res)
178 }); 178 })
179 } 179 }
180 180
181 refreshUserInformations() { 181 refreshUserInformations () {
182 const obj = { 182 const obj = {
183 access_token: this.user.getAccessToken() 183 access_token: this.user.getAccessToken()
184 }; 184 }
185 185
186 this.mergeUserInformations(obj) 186 this.mergeUserInformations (obj)
187 .subscribe( 187 .subscribe(
188 res => { 188 res => {
189 this.user.displayNSFW = res.displayNSFW; 189 this.user.displayNSFW = res.displayNSFW
190 this.user.role = res.role; 190 this.user.role = res.role
191 191
192 this.user.save(); 192 this.user.save()
193 } 193 }
194 ); 194 )
195 } 195 }
196 196
197 private mergeUserInformations(obj: { access_token: string }) { 197 private mergeUserInformations (obj: { access_token: string }) {
198 // Do not call authHttp here to avoid circular dependencies headaches 198 // Do not call authHttp here to avoid circular dependencies headaches
199 199
200 const headers = new Headers(); 200 const headers = new Headers()
201 headers.set('Authorization', `Bearer ${obj.access_token}`); 201 headers.set('Authorization', `Bearer ${obj.access_token}`)
202 202
203 return this.http.get(AuthService.BASE_USER_INFORMATIONS_URL, { headers }) 203 return this.http.get(AuthService.BASE_USER_INFORMATIONS_URL, { headers })
204 .map(res => res.json()) 204 .map(res => res.json())
@@ -207,38 +207,38 @@ export class AuthService {
207 id: res.id, 207 id: res.id,
208 role: res.role, 208 role: res.role,
209 displayNSFW: res.displayNSFW 209 displayNSFW: res.displayNSFW
210 }; 210 }
211 211
212 return Object.assign(obj, newProperties); 212 return Object.assign(obj, newProperties)
213 } 213 }
214 ); 214 )
215 } 215 }
216 216
217 private handleLogin (obj: any) { 217 private handleLogin (obj: any) {
218 const id = obj.id; 218 const id = obj.id
219 const username = obj.username; 219 const username = obj.username
220 const role = obj.role; 220 const role = obj.role
221 const email = obj.email; 221 const email = obj.email
222 const displayNSFW = obj.displayNSFW; 222 const displayNSFW = obj.displayNSFW
223 const hashTokens = { 223 const hashTokens = {
224 access_token: obj.access_token, 224 accessToken: obj.access_token,
225 token_type: obj.token_type, 225 tokenType: obj.token_type,
226 refresh_token: obj.refresh_token 226 refreshToken: obj.refresh_token
227 }; 227 }
228 228
229 this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens); 229 this.user = new AuthUser({ id, username, role, displayNSFW, email }, hashTokens)
230 this.user.save(); 230 this.user.save()
231 231
232 this.setStatus(AuthStatus.LoggedIn); 232 this.setStatus(AuthStatus.LoggedIn)
233 } 233 }
234 234
235 private handleRefreshToken (obj: any) { 235 private handleRefreshToken (obj: any) {
236 this.user.refreshTokens(obj.access_token, obj.refresh_token); 236 this.user.refreshTokens(obj.access_token, obj.refresh_token)
237 this.user.save(); 237 this.user.save()
238 } 238 }
239 239
240 private setStatus(status: AuthStatus) { 240 private setStatus (status: AuthStatus) {
241 this.loginChanged.next(status); 241 this.loginChanged.next(status)
242 } 242 }
243 243
244} 244}
diff --git a/client/src/app/core/auth/index.ts b/client/src/app/core/auth/index.ts
index 67a18cfbb..8e5caa7ed 100644
--- a/client/src/app/core/auth/index.ts
+++ b/client/src/app/core/auth/index.ts
@@ -1,3 +1,3 @@
1export * from './auth-status.model'; 1export * from './auth-status.model'
2export * from './auth-user.model'; 2export * from './auth-user.model'
3export * from './auth.service' 3export * from './auth.service'
diff --git a/client/src/app/core/config/config.service.ts b/client/src/app/core/config/config.service.ts
index 407dca083..a83ec61d2 100644
--- a/client/src/app/core/config/config.service.ts
+++ b/client/src/app/core/config/config.service.ts
@@ -1,11 +1,11 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Http } from '@angular/http'; 2import { Http } from '@angular/http'
3 3
4import { RestExtractor } from '../../shared/rest'; 4import { RestExtractor } from '../../shared/rest'
5 5
6@Injectable() 6@Injectable()
7export class ConfigService { 7export class ConfigService {
8 private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'; 8 private static BASE_CONFIG_URL = API_URL + '/api/v1/config/'
9 9
10 private config: { 10 private config: {
11 signup: { 11 signup: {
@@ -15,22 +15,22 @@ export class ConfigService {
15 signup: { 15 signup: {
16 enabled: false 16 enabled: false
17 } 17 }
18 }; 18 }
19 19
20 constructor( 20 constructor (
21 private http: Http, 21 private http: Http,
22 private restExtractor: RestExtractor, 22 private restExtractor: RestExtractor
23 ) {} 23 ) {}
24 24
25 loadConfig() { 25 loadConfig () {
26 this.http.get(ConfigService.BASE_CONFIG_URL) 26 this.http.get(ConfigService.BASE_CONFIG_URL)
27 .map(this.restExtractor.extractDataGet) 27 .map(this.restExtractor.extractDataGet)
28 .subscribe(data => { 28 .subscribe(data => {
29 this.config = data; 29 this.config = data
30 }); 30 })
31 } 31 }
32 32
33 getConfig() { 33 getConfig () {
34 return this.config; 34 return this.config
35 } 35 }
36} 36}
diff --git a/client/src/app/core/config/index.ts b/client/src/app/core/config/index.ts
index 90392254a..3724e12f2 100644
--- a/client/src/app/core/config/index.ts
+++ b/client/src/app/core/config/index.ts
@@ -1 +1 @@
export * from './config.service'; export * from './config.service'
diff --git a/client/src/app/core/confirm/confirm.component.ts b/client/src/app/core/confirm/confirm.component.ts
index ae42ff68a..066e3fc5f 100644
--- a/client/src/app/core/confirm/confirm.component.ts
+++ b/client/src/app/core/confirm/confirm.component.ts
@@ -1,12 +1,12 @@
1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'; 1import { Component, HostListener, OnInit, ViewChild } from '@angular/core'
2 2
3import { ModalDirective } from 'ngx-bootstrap/modal'; 3import { ModalDirective } from 'ngx-bootstrap/modal'
4 4
5import { ConfirmService } from './confirm.service'; 5import { ConfirmService } from './confirm.service'
6 6
7export interface ConfigChangedEvent { 7export interface ConfigChangedEvent {
8 columns: { [id: string]: { isDisplayed: boolean }; }; 8 columns: { [id: string]: { isDisplayed: boolean } }
9 config: { resultsPerPage: number }; 9 config: { resultsPerPage: number }
10} 10}
11 11
12@Component({ 12@Component({
@@ -14,48 +14,48 @@ export interface ConfigChangedEvent {
14 templateUrl: './confirm.component.html' 14 templateUrl: './confirm.component.html'
15}) 15})
16export class ConfirmComponent implements OnInit { 16export class ConfirmComponent implements OnInit {
17 @ViewChild('confirmModal') confirmModal: ModalDirective; 17 @ViewChild('confirmModal') confirmModal: ModalDirective
18 18
19 title = ''; 19 title = ''
20 message = ''; 20 message = ''
21 21
22 constructor (private confirmService: ConfirmService) { 22 constructor (private confirmService: ConfirmService) {
23 // Empty 23 // Empty
24 } 24 }
25 25
26 ngOnInit() { 26 ngOnInit () {
27 this.confirmModal.config = { 27 this.confirmModal.config = {
28 backdrop: 'static', 28 backdrop: 'static',
29 keyboard: false 29 keyboard: false
30 }; 30 }
31 31
32 this.confirmService.showConfirm.subscribe( 32 this.confirmService.showConfirm.subscribe(
33 ({ title, message }) => { 33 ({ title, message }) => {
34 this.title = title; 34 this.title = title
35 this.message = message; 35 this.message = message
36 36
37 this.showModal(); 37 this.showModal()
38 } 38 }
39 ); 39 )
40 } 40 }
41 41
42 @HostListener('keydown.enter') 42 @HostListener('keydown.enter')
43 confirm() { 43 confirm () {
44 this.confirmService.confirmResponse.next(true); 44 this.confirmService.confirmResponse.next(true)
45 this.hideModal(); 45 this.hideModal()
46 } 46 }
47 47
48 @HostListener('keydown.esc') 48 @HostListener('keydown.esc')
49 abort() { 49 abort () {
50 this.confirmService.confirmResponse.next(false); 50 this.confirmService.confirmResponse.next(false)
51 this.hideModal(); 51 this.hideModal()
52 } 52 }
53 53
54 showModal() { 54 showModal () {
55 this.confirmModal.show(); 55 this.confirmModal.show()
56 } 56 }
57 57
58 hideModal() { 58 hideModal () {
59 this.confirmModal.hide(); 59 this.confirmModal.hide()
60 } 60 }
61} 61}
diff --git a/client/src/app/core/confirm/confirm.service.ts b/client/src/app/core/confirm/confirm.service.ts
index 08127a66f..f12ff1848 100644
--- a/client/src/app/core/confirm/confirm.service.ts
+++ b/client/src/app/core/confirm/confirm.service.ts
@@ -1,15 +1,15 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Subject } from 'rxjs/Subject'; 2import { Subject } from 'rxjs/Subject'
3import 'rxjs/add/operator/first'; 3import 'rxjs/add/operator/first'
4 4
5@Injectable() 5@Injectable()
6export class ConfirmService { 6export class ConfirmService {
7 showConfirm = new Subject<{ title, message }>(); 7 showConfirm = new Subject<{ title, message }>()
8 confirmResponse = new Subject<boolean>(); 8 confirmResponse = new Subject<boolean>()
9 9
10 confirm(message = '', title = '') { 10 confirm (message = '', title = '') {
11 this.showConfirm.next({ title, message }); 11 this.showConfirm.next({ title, message })
12 12
13 return this.confirmResponse.asObservable().first(); 13 return this.confirmResponse.asObservable().first()
14 } 14 }
15} 15}
diff --git a/client/src/app/core/confirm/index.ts b/client/src/app/core/confirm/index.ts
index 789e7e547..44aabfc13 100644
--- a/client/src/app/core/confirm/index.ts
+++ b/client/src/app/core/confirm/index.ts
@@ -1,2 +1,2 @@
1export * from './confirm.component'; 1export * from './confirm.component'
2export * from './confirm.service'; 2export * from './confirm.service'
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts
index 81c8f2da6..382febe5c 100644
--- a/client/src/app/core/core.module.ts
+++ b/client/src/app/core/core.module.ts
@@ -1,16 +1,16 @@
1import { NgModule, Optional, SkipSelf } from '@angular/core'; 1import { NgModule, Optional, SkipSelf } from '@angular/core'
2import { CommonModule } from '@angular/common'; 2import { CommonModule } from '@angular/common'
3import { HttpModule } from '@angular/http'; 3import { HttpModule } from '@angular/http'
4import { RouterModule } from '@angular/router'; 4import { RouterModule } from '@angular/router'
5 5
6import { SimpleNotificationsModule } from 'angular2-notifications'; 6import { SimpleNotificationsModule } from 'angular2-notifications'
7import { ModalModule } from 'ngx-bootstrap/modal'; 7import { ModalModule } from 'ngx-bootstrap/modal'
8 8
9import { AuthService } from './auth'; 9import { AuthService } from './auth'
10import { ConfigService } from './config'; 10import { ConfigService } from './config'
11import { ConfirmComponent, ConfirmService } from './confirm'; 11import { ConfirmComponent, ConfirmService } from './confirm'
12import { MenuComponent, MenuAdminComponent } from './menu'; 12import { MenuComponent, MenuAdminComponent } from './menu'
13import { throwIfAlreadyLoaded } from './module-import-guard'; 13import { throwIfAlreadyLoaded } from './module-import-guard'
14 14
15@NgModule({ 15@NgModule({
16 imports: [ 16 imports: [
@@ -43,7 +43,7 @@ import { throwIfAlreadyLoaded } from './module-import-guard';
43 ] 43 ]
44}) 44})
45export class CoreModule { 45export class CoreModule {
46 constructor( @Optional() @SkipSelf() parentModule: CoreModule) { 46 constructor ( @Optional() @SkipSelf() parentModule: CoreModule) {
47 throwIfAlreadyLoaded(parentModule, 'CoreModule'); 47 throwIfAlreadyLoaded(parentModule, 'CoreModule')
48 } 48 }
49} 49}
diff --git a/client/src/app/core/index.ts b/client/src/app/core/index.ts
index 96b28658b..01b12ce7e 100644
--- a/client/src/app/core/index.ts
+++ b/client/src/app/core/index.ts
@@ -1,5 +1,5 @@
1export * from './auth'; 1export * from './auth'
2export * from './config'; 2export * from './config'
3export * from './confirm'; 3export * from './confirm'
4export * from './menu'; 4export * from './menu'
5export * from './core.module' 5export * from './core.module'
diff --git a/client/src/app/core/menu/index.ts b/client/src/app/core/menu/index.ts
index ff40f26e1..c905ed20a 100644
--- a/client/src/app/core/menu/index.ts
+++ b/client/src/app/core/menu/index.ts
@@ -1,2 +1,2 @@
1export * from './menu.component'; 1export * from './menu.component'
2export * from './menu-admin.component'; 2export * from './menu-admin.component'
diff --git a/client/src/app/core/menu/menu-admin.component.ts b/client/src/app/core/menu/menu-admin.component.ts
index 236161fce..f6cc6554c 100644
--- a/client/src/app/core/menu/menu-admin.component.ts
+++ b/client/src/app/core/menu/menu-admin.component.ts
@@ -1,4 +1,4 @@
1import { Component } from '@angular/core'; 1import { Component } from '@angular/core'
2 2
3@Component({ 3@Component({
4 selector: 'my-menu-admin', 4 selector: 'my-menu-admin',
diff --git a/client/src/app/core/menu/menu.component.ts b/client/src/app/core/menu/menu.component.ts
index 5ab8bf464..b725f64a7 100644
--- a/client/src/app/core/menu/menu.component.ts
+++ b/client/src/app/core/menu/menu.component.ts
@@ -1,8 +1,8 @@
1import { Component, OnInit } from '@angular/core'; 1import { Component, OnInit } from '@angular/core'
2import { Router } from '@angular/router'; 2import { Router } from '@angular/router'
3 3
4import { AuthService, AuthStatus } from '../auth'; 4import { AuthService, AuthStatus } from '../auth'
5import { ConfigService } from '../config'; 5import { ConfigService } from '../config'
6 6
7@Component({ 7@Component({
8 selector: 'my-menu', 8 selector: 'my-menu',
@@ -10,7 +10,7 @@ import { ConfigService } from '../config';
10 styleUrls: [ './menu.component.scss' ] 10 styleUrls: [ './menu.component.scss' ]
11}) 11})
12export class MenuComponent implements OnInit { 12export class MenuComponent implements OnInit {
13 isLoggedIn: boolean; 13 isLoggedIn: boolean
14 14
15 constructor ( 15 constructor (
16 private authService: AuthService, 16 private authService: AuthService,
@@ -18,35 +18,35 @@ export class MenuComponent implements OnInit {
18 private router: Router 18 private router: Router
19 ) {} 19 ) {}
20 20
21 ngOnInit() { 21 ngOnInit () {
22 this.isLoggedIn = this.authService.isLoggedIn(); 22 this.isLoggedIn = this.authService.isLoggedIn()
23 23
24 this.authService.loginChangedSource.subscribe( 24 this.authService.loginChangedSource.subscribe(
25 status => { 25 status => {
26 if (status === AuthStatus.LoggedIn) { 26 if (status === AuthStatus.LoggedIn) {
27 this.isLoggedIn = true; 27 this.isLoggedIn = true
28 console.log('Logged in.'); 28 console.log('Logged in.')
29 } else if (status === AuthStatus.LoggedOut) { 29 } else if (status === AuthStatus.LoggedOut) {
30 this.isLoggedIn = false; 30 this.isLoggedIn = false
31 console.log('Logged out.'); 31 console.log('Logged out.')
32 } else { 32 } else {
33 console.error('Unknown auth status: ' + status); 33 console.error('Unknown auth status: ' + status)
34 } 34 }
35 } 35 }
36 ); 36 )
37 } 37 }
38 38
39 isRegistrationEnabled() { 39 isRegistrationEnabled () {
40 return this.configService.getConfig().signup.enabled; 40 return this.configService.getConfig().signup.enabled
41 } 41 }
42 42
43 isUserAdmin() { 43 isUserAdmin () {
44 return this.authService.isAdmin(); 44 return this.authService.isAdmin()
45 } 45 }
46 46
47 logout() { 47 logout () {
48 this.authService.logout(); 48 this.authService.logout()
49 // Redirect to home page 49 // Redirect to home page
50 this.router.navigate(['/videos/list']); 50 this.router.navigate(['/videos/list'])
51 } 51 }
52} 52}
diff --git a/client/src/app/core/module-import-guard.ts b/client/src/app/core/module-import-guard.ts
index 445640c4f..32b1d8f19 100644
--- a/client/src/app/core/module-import-guard.ts
+++ b/client/src/app/core/module-import-guard.ts
@@ -1,5 +1,5 @@
1export function throwIfAlreadyLoaded(parentModule: any, moduleName: string) { 1export function throwIfAlreadyLoaded (parentModule: any, moduleName: string) {
2 if (parentModule) { 2 if (parentModule) {
3 throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`); 3 throw new Error(`${moduleName} has already been loaded. Import Core modules in the AppModule only.`)
4 } 4 }
5} 5}