aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-03-04 11:45:47 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-03-04 11:45:47 +0100
commite2a2d6c86c7ca39074fdff3b545947d1d58dc008 (patch)
treea3420493460f67472acceae2a5746612a30943f0 /client/src/app
parenta7449e74f9105839fa03f0b2e23b435f37a1fc2f (diff)
downloadPeerTube-e2a2d6c86c7ca39074fdff3b545947d1d58dc008.tar.gz
PeerTube-e2a2d6c86c7ca39074fdff3b545947d1d58dc008.tar.zst
PeerTube-e2a2d6c86c7ca39074fdff3b545947d1d58dc008.zip
Client: check token valitidy at startup
Diffstat (limited to 'client/src/app')
-rw-r--r--client/src/app/account/account.component.ts7
-rw-r--r--client/src/app/account/account.module.ts4
-rw-r--r--client/src/app/account/index.ts1
-rw-r--r--client/src/app/app.component.ts18
-rw-r--r--client/src/app/core/auth/auth-status.model.ts (renamed from client/src/app/shared/auth/auth-status.model.ts)0
-rw-r--r--client/src/app/core/auth/auth-user.model.ts (renamed from client/src/app/shared/auth/auth-user.model.ts)3
-rw-r--r--client/src/app/core/auth/auth.service.ts4
-rw-r--r--client/src/app/core/auth/index.ts2
-rw-r--r--client/src/app/core/menu/menu.component.ts3
-rw-r--r--client/src/app/shared/auth/index.ts2
-rw-r--r--client/src/app/shared/shared.module.ts4
-rw-r--r--client/src/app/shared/users/index.ts1
-rw-r--r--client/src/app/shared/users/user.service.ts (renamed from client/src/app/account/account.service.ts)16
-rw-r--r--client/src/app/videos/video-list/video-list.component.ts4
14 files changed, 44 insertions, 25 deletions
diff --git a/client/src/app/account/account.component.ts b/client/src/app/account/account.component.ts
index 9b6b5fbf4..14452a73e 100644
--- a/client/src/app/account/account.component.ts
+++ b/client/src/app/account/account.component.ts
@@ -4,8 +4,7 @@ import { Router } from '@angular/router';
4 4
5import { NotificationsService } from 'angular2-notifications'; 5import { NotificationsService } from 'angular2-notifications';
6 6
7import { AccountService } from './account.service'; 7import { FormReactive, UserService, USER_PASSWORD } from '../shared';
8import { FormReactive, USER_PASSWORD } from '../shared';
9 8
10@Component({ 9@Component({
11 selector: 'my-account', 10 selector: 'my-account',
@@ -29,7 +28,7 @@ export class AccountComponent extends FormReactive implements OnInit {
29 private formBuilder: FormBuilder, 28 private formBuilder: FormBuilder,
30 private router: Router, 29 private router: Router,
31 private notificationsService: NotificationsService, 30 private notificationsService: NotificationsService,
32 private accountService: AccountService 31 private userService: UserService
33 ) { 32 ) {
34 super(); 33 super();
35 } 34 }
@@ -58,7 +57,7 @@ export class AccountComponent extends FormReactive implements OnInit {
58 return; 57 return;
59 } 58 }
60 59
61 this.accountService.changePassword(newPassword).subscribe( 60 this.userService.changePassword(newPassword).subscribe(
62 () => this.notificationsService.success('Success', 'Password updated.'), 61 () => this.notificationsService.success('Success', 'Password updated.'),
63 62
64 err => this.error = err 63 err => this.error = err
diff --git a/client/src/app/account/account.module.ts b/client/src/app/account/account.module.ts
index 53f6ba58e..75f2ee6f9 100644
--- a/client/src/app/account/account.module.ts
+++ b/client/src/app/account/account.module.ts
@@ -19,8 +19,6 @@ import { SharedModule } from '../shared';
19 AccountComponent 19 AccountComponent
20 ], 20 ],
21 21
22 providers: [ 22 providers: []
23 AccountService
24 ]
25}) 23})
26export class AccountModule { } 24export class AccountModule { }
diff --git a/client/src/app/account/index.ts b/client/src/app/account/index.ts
index be03713cb..9265fa10a 100644
--- a/client/src/app/account/index.ts
+++ b/client/src/app/account/index.ts
@@ -1,4 +1,3 @@
1export * from './account-routing.module'; 1export * from './account-routing.module';
2export * from './account.component'; 2export * from './account.component';
3export * from './account.module'; 3export * from './account.module';
4export * from './account.service';
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts
index f487e6c48..47d2bfdd2 100644
--- a/client/src/app/app.component.ts
+++ b/client/src/app/app.component.ts
@@ -1,14 +1,17 @@
1import { Component, ViewContainerRef } from '@angular/core'; 1import { Component, OnInit, ViewContainerRef } from '@angular/core';
2import { Router } from '@angular/router'; 2import { Router } from '@angular/router';
3 3
4import { MetaService } from 'ng2-meta'; 4import { MetaService } from 'ng2-meta';
5
6import { AuthService } from './core';
7import { UserService } from './shared';
8
5@Component({ 9@Component({
6 selector: 'my-app', 10 selector: 'my-app',
7 templateUrl: './app.component.html', 11 templateUrl: './app.component.html',
8 styleUrls: [ './app.component.scss' ] 12 styleUrls: [ './app.component.scss' ]
9}) 13})
10 14export class AppComponent implements OnInit {
11export class AppComponent {
12 notificationOptions = { 15 notificationOptions = {
13 timeOut: 3000, 16 timeOut: 3000,
14 lastOnBottom: true, 17 lastOnBottom: true,
@@ -25,9 +28,18 @@ export class AppComponent {
25 constructor( 28 constructor(
26 private router: Router, 29 private router: Router,
27 private metaService: MetaService, 30 private metaService: MetaService,
31 private authService: AuthService,
32 private userService: UserService,
28 viewContainerRef: ViewContainerRef 33 viewContainerRef: ViewContainerRef
29 ) {} 34 ) {}
30 35
36 ngOnInit() {
37 if (this.authService.isLoggedIn()) {
38 // The service will automatically redirect to the login page if the token is not valid anymore
39 this.userService.checkTokenValidity();
40 }
41 }
42
31 isInAdmin() { 43 isInAdmin() {
32 return this.router.url.indexOf('/admin/') !== -1; 44 return this.router.url.indexOf('/admin/') !== -1;
33 } 45 }
diff --git a/client/src/app/shared/auth/auth-status.model.ts b/client/src/app/core/auth/auth-status.model.ts
index f646bd4cf..f646bd4cf 100644
--- a/client/src/app/shared/auth/auth-status.model.ts
+++ b/client/src/app/core/auth/auth-status.model.ts
diff --git a/client/src/app/shared/auth/auth-user.model.ts b/client/src/app/core/auth/auth-user.model.ts
index f560351f4..5d61954d6 100644
--- a/client/src/app/shared/auth/auth-user.model.ts
+++ b/client/src/app/core/auth/auth-user.model.ts
@@ -1,4 +1,5 @@
1import { User } from '../users'; 1// Do not use the barrel (dependency loop)
2import { User } from '../../shared/users/user.model';
2 3
3export class AuthUser extends User { 4export class AuthUser extends User {
4 private static KEYS = { 5 private static KEYS = {
diff --git a/client/src/app/core/auth/auth.service.ts b/client/src/app/core/auth/auth.service.ts
index a56adbbad..2e7328197 100644
--- a/client/src/app/core/auth/auth.service.ts
+++ b/client/src/app/core/auth/auth.service.ts
@@ -9,9 +9,9 @@ import 'rxjs/add/observable/throw';
9 9
10import { NotificationsService } from 'angular2-notifications'; 10import { NotificationsService } from 'angular2-notifications';
11 11
12import { AuthStatus } from './auth-status.model';
13import { AuthUser } from './auth-user.model';
12// Do not use the barrel (dependency loop) 14// Do not use the barrel (dependency loop)
13import { AuthStatus } from '../../shared/auth/auth-status.model';
14import { AuthUser } from '../../shared/auth/auth-user.model';
15import { RestExtractor } from '../../shared/rest'; 15import { RestExtractor } from '../../shared/rest';
16 16
17@Injectable() 17@Injectable()
diff --git a/client/src/app/core/auth/index.ts b/client/src/app/core/auth/index.ts
index cf52c9c7c..67a18cfbb 100644
--- a/client/src/app/core/auth/index.ts
+++ b/client/src/app/core/auth/index.ts
@@ -1 +1,3 @@
1export * from './auth-status.model';
2export * from './auth-user.model';
1export * from './auth.service' 3export * from './auth.service'
diff --git a/client/src/app/core/menu/menu.component.ts b/client/src/app/core/menu/menu.component.ts
index f1bf6966d..5ca60e5e0 100644
--- a/client/src/app/core/menu/menu.component.ts
+++ b/client/src/app/core/menu/menu.component.ts
@@ -1,8 +1,7 @@
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 } from '../auth'; 4import { AuthService, AuthStatus } from '../auth';
5import { AuthStatus } from '../../shared';
6 5
7@Component({ 6@Component({
8 selector: 'my-menu', 7 selector: 'my-menu',
diff --git a/client/src/app/shared/auth/index.ts b/client/src/app/shared/auth/index.ts
index ce0bd8adf..c488aed69 100644
--- a/client/src/app/shared/auth/index.ts
+++ b/client/src/app/shared/auth/index.ts
@@ -1,3 +1 @@
1export * from './auth-http.service'; export * from './auth-http.service';
2export * from './auth-status.model';
3export * from './auth-user.model';
diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts
index 0f57ef078..84cc86c64 100644
--- a/client/src/app/shared/shared.module.ts
+++ b/client/src/app/shared/shared.module.ts
@@ -16,6 +16,7 @@ import { Ng2SmartTableModule } from 'ng2-smart-table';
16import { AUTH_HTTP_PROVIDERS } from './auth'; 16import { AUTH_HTTP_PROVIDERS } from './auth';
17import { RestExtractor, RestService } from './rest'; 17import { RestExtractor, RestService } from './rest';
18import { SearchComponent, SearchService } from './search'; 18import { SearchComponent, SearchService } from './search';
19import { UserService } from './users';
19import { VideoAbuseService } from './video-abuse'; 20import { VideoAbuseService } from './video-abuse';
20 21
21@NgModule({ 22@NgModule({
@@ -65,7 +66,8 @@ import { VideoAbuseService } from './video-abuse';
65 RestExtractor, 66 RestExtractor,
66 RestService, 67 RestService,
67 SearchService, 68 SearchService,
68 VideoAbuseService 69 VideoAbuseService,
70 UserService
69 ] 71 ]
70}) 72})
71export class SharedModule { } 73export class SharedModule { }
diff --git a/client/src/app/shared/users/index.ts b/client/src/app/shared/users/index.ts
index 5a670ce8f..ff009e89b 100644
--- a/client/src/app/shared/users/index.ts
+++ b/client/src/app/shared/users/index.ts
@@ -1 +1,2 @@
1export * from './user.model'; 1export * from './user.model';
2export * from './user.service';
diff --git a/client/src/app/account/account.service.ts b/client/src/app/shared/users/user.service.ts
index 046690347..4cf100f0d 100644
--- a/client/src/app/account/account.service.ts
+++ b/client/src/app/shared/users/user.service.ts
@@ -2,11 +2,12 @@ import { Injectable } from '@angular/core';
2import 'rxjs/add/operator/catch'; 2import 'rxjs/add/operator/catch';
3import 'rxjs/add/operator/map'; 3import 'rxjs/add/operator/map';
4 4
5import { AuthService } from '../core'; 5import { AuthService } from '../../core';
6import { AuthHttp, RestExtractor } from '../shared'; 6import { AuthHttp } from '../auth';
7import { RestExtractor } from '../rest';
7 8
8@Injectable() 9@Injectable()
9export class AccountService { 10export class UserService {
10 private static BASE_USERS_URL = '/api/v1/users/'; 11 private static BASE_USERS_URL = '/api/v1/users/';
11 12
12 constructor( 13 constructor(
@@ -15,8 +16,15 @@ export class AccountService {
15 private restExtractor: RestExtractor 16 private restExtractor: RestExtractor
16 ) {} 17 ) {}
17 18
19 checkTokenValidity() {
20 const url = UserService.BASE_USERS_URL + 'me';
21
22 // AuthHttp will redirect us to the login page if the oken is not valid anymore
23 this.authHttp.get(url).subscribe(() => { ; });
24 }
25
18 changePassword(newPassword: string) { 26 changePassword(newPassword: string) {
19 const url = AccountService.BASE_USERS_URL + this.authService.getUser().id; 27 const url = UserService.BASE_USERS_URL + this.authService.getUser().id;
20 const body = { 28 const body = {
21 password: newPassword 29 password: newPassword
22 }; 30 };
diff --git a/client/src/app/videos/video-list/video-list.component.ts b/client/src/app/videos/video-list/video-list.component.ts
index b3780f8b6..844e14567 100644
--- a/client/src/app/videos/video-list/video-list.component.ts
+++ b/client/src/app/videos/video-list/video-list.component.ts
@@ -9,8 +9,8 @@ import {
9 Video, 9 Video,
10 VideoService 10 VideoService
11} from '../shared'; 11} from '../shared';
12import { AuthService } from '../../core'; 12import { AuthService, AuthUser } from '../../core';
13import { AuthUser, RestPagination, Search, SearchField } from '../../shared'; 13import { RestPagination, Search, SearchField } from '../../shared';
14import { SearchService } from '../../shared'; 14import { SearchService } from '../../shared';
15 15
16@Component({ 16@Component({