aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-04-04 21:37:03 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-04-04 21:37:03 +0200
commit92fb909c9b4a92a00b0d0da7629e6fb003de281b (patch)
tree8119c6720d5dec0474983501843f1e699fde150a /client/src/app/core
parent1d49e1e27d63db1dfc9a7fd28c9902f488831a89 (diff)
downloadPeerTube-92fb909c9b4a92a00b0d0da7629e6fb003de281b.tar.gz
PeerTube-92fb909c9b4a92a00b0d0da7629e6fb003de281b.tar.zst
PeerTube-92fb909c9b4a92a00b0d0da7629e6fb003de281b.zip
Client: Handle NSFW video
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/auth/auth-user.model.ts15
-rw-r--r--client/src/app/core/config/config.service.ts36
-rw-r--r--client/src/app/core/config/index.ts1
-rw-r--r--client/src/app/core/core.module.ts4
-rw-r--r--client/src/app/core/index.ts1
5 files changed, 53 insertions, 4 deletions
diff --git a/client/src/app/core/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts
index 5d61954d6..cb7e88d19 100644
--- a/client/src/app/core/auth/auth-user.model.ts
+++ b/client/src/app/core/auth/auth-user.model.ts
@@ -5,7 +5,8 @@ export class AuthUser extends User {
5 private static KEYS = { 5 private static KEYS = {
6 ID: 'id', 6 ID: 'id',
7 ROLE: 'role', 7 ROLE: 'role',
8 USERNAME: 'username' 8 USERNAME: 'username',
9 DISPLAY_NSFW: 'display_nsfw'
9 }; 10 };
10 11
11 tokens: Tokens; 12 tokens: Tokens;
@@ -17,7 +18,8 @@ export class AuthUser extends User {
17 { 18 {
18 id: parseInt(localStorage.getItem(this.KEYS.ID)), 19 id: parseInt(localStorage.getItem(this.KEYS.ID)),
19 username: localStorage.getItem(this.KEYS.USERNAME), 20 username: localStorage.getItem(this.KEYS.USERNAME),
20 role: localStorage.getItem(this.KEYS.ROLE) 21 role: localStorage.getItem(this.KEYS.ROLE),
22 displayNSFW: localStorage.getItem(this.KEYS.DISPLAY_NSFW) === 'true'
21 }, 23 },
22 Tokens.load() 24 Tokens.load()
23 ); 25 );
@@ -30,10 +32,16 @@ export class AuthUser extends User {
30 localStorage.removeItem(this.KEYS.USERNAME); 32 localStorage.removeItem(this.KEYS.USERNAME);
31 localStorage.removeItem(this.KEYS.ID); 33 localStorage.removeItem(this.KEYS.ID);
32 localStorage.removeItem(this.KEYS.ROLE); 34 localStorage.removeItem(this.KEYS.ROLE);
35 localStorage.removeItem(this.KEYS.DISPLAY_NSFW);
33 Tokens.flush(); 36 Tokens.flush();
34 } 37 }
35 38
36 constructor(userHash: { id: number, username: string, role: string }, hashTokens: any) { 39 constructor(userHash: {
40 id: number,
41 username: string,
42 role: string,
43 displayNSFW: boolean
44 }, hashTokens: any) {
37 super(userHash); 45 super(userHash);
38 this.tokens = new Tokens(hashTokens); 46 this.tokens = new Tokens(hashTokens);
39 } 47 }
@@ -59,6 +67,7 @@ export class AuthUser extends User {
59 localStorage.setItem(AuthUser.KEYS.ID, this.id.toString()); 67 localStorage.setItem(AuthUser.KEYS.ID, this.id.toString());
60 localStorage.setItem(AuthUser.KEYS.USERNAME, this.username); 68 localStorage.setItem(AuthUser.KEYS.USERNAME, this.username);
61 localStorage.setItem(AuthUser.KEYS.ROLE, this.role); 69 localStorage.setItem(AuthUser.KEYS.ROLE, this.role);
70 localStorage.setItem(AuthUser.KEYS.DISPLAY_NSFW, JSON.stringify(this.displayNSFW);
62 this.tokens.save(); 71 this.tokens.save();
63 } 72 }
64} 73}
diff --git a/client/src/app/core/config/config.service.ts b/client/src/app/core/config/config.service.ts
new file mode 100644
index 000000000..295e68c36
--- /dev/null
+++ b/client/src/app/core/config/config.service.ts
@@ -0,0 +1,36 @@
1import { Injectable } from '@angular/core';
2import { Http } from '@angular/http';
3
4import { RestExtractor } from '../../shared/rest';
5
6@Injectable()
7export class ConfigService {
8 private static BASE_CONFIG_URL = '/api/v1/config/';
9
10 private config: {
11 signup: {
12 enabled: boolean
13 }
14 } = {
15 signup: {
16 enabled: false
17 }
18 };
19
20 constructor(
21 private http: Http,
22 private restExtractor: RestExtractor,
23 ) {}
24
25 loadConfig() {
26 this.http.get(ConfigService.BASE_CONFIG_URL)
27 .map(this.restExtractor.extractDataGet)
28 .subscribe(data => {
29 this.config = data;
30 });
31 }
32
33 getConfig() {
34 return this.config;
35 }
36}
diff --git a/client/src/app/core/config/index.ts b/client/src/app/core/config/index.ts
new file mode 100644
index 000000000..90392254a
--- /dev/null
+++ b/client/src/app/core/config/index.ts
@@ -0,0 +1 @@
export * from './config.service';
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts
index ae2930552..9a5ee5221 100644
--- a/client/src/app/core/core.module.ts
+++ b/client/src/app/core/core.module.ts
@@ -7,6 +7,7 @@ import { SimpleNotificationsModule } from 'angular2-notifications';
7import { ModalModule } from 'ng2-bootstrap/modal'; 7import { ModalModule } from 'ng2-bootstrap/modal';
8 8
9import { AuthService } from './auth'; 9import { AuthService } from './auth';
10import { ConfigService } from './config';
10import { ConfirmComponent, ConfirmService } from './confirm'; 11import { ConfirmComponent, ConfirmService } from './confirm';
11import { MenuComponent, MenuAdminComponent } from './menu'; 12import { MenuComponent, MenuAdminComponent } from './menu';
12import { throwIfAlreadyLoaded } from './module-import-guard'; 13import { throwIfAlreadyLoaded } from './module-import-guard';
@@ -37,7 +38,8 @@ import { throwIfAlreadyLoaded } from './module-import-guard';
37 38
38 providers: [ 39 providers: [
39 AuthService, 40 AuthService,
40 ConfirmService 41 ConfirmService,
42 ConfigService
41 ] 43 ]
42}) 44})
43export class CoreModule { 45export class CoreModule {
diff --git a/client/src/app/core/index.ts b/client/src/app/core/index.ts
index 9b4dd1999..96b28658b 100644
--- a/client/src/app/core/index.ts
+++ b/client/src/app/core/index.ts
@@ -1,4 +1,5 @@
1export * from './auth'; 1export * from './auth';
2export * from './config';
2export * from './confirm'; 3export * from './confirm';
3export * from './menu'; 4export * from './menu';
4export * from './core.module' 5export * from './core.module'