aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/core
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-10-10 10:18:25 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-10-10 10:24:02 +0200
commitf47bf2e142b0b22460558e23720f5aed8deb982c (patch)
tree63a084494585a67e4326bf18c611e108de59aaee /client/src/app/core
parent35bf0c83c80f59ca79f4b84fac8700f17adeb22d (diff)
downloadPeerTube-f47bf2e142b0b22460558e23720f5aed8deb982c.tar.gz
PeerTube-f47bf2e142b0b22460558e23720f5aed8deb982c.tar.zst
PeerTube-f47bf2e142b0b22460558e23720f5aed8deb982c.zip
Client: check user is logged in for some pages
Diffstat (limited to 'client/src/app/core')
-rw-r--r--client/src/app/core/auth/index.ts1
-rw-r--r--client/src/app/core/auth/login-guard.service.ts30
-rw-r--r--client/src/app/core/core.module.ts5
-rw-r--r--client/src/app/core/menu/menu.component.html2
4 files changed, 35 insertions, 3 deletions
diff --git a/client/src/app/core/auth/index.ts b/client/src/app/core/auth/index.ts
index 8e5caa7ed..a81f2c002 100644
--- a/client/src/app/core/auth/index.ts
+++ b/client/src/app/core/auth/index.ts
@@ -1,3 +1,4 @@
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'
4export * from './login-guard.service'
diff --git a/client/src/app/core/auth/login-guard.service.ts b/client/src/app/core/auth/login-guard.service.ts
new file mode 100644
index 000000000..c09e8fe97
--- /dev/null
+++ b/client/src/app/core/auth/login-guard.service.ts
@@ -0,0 +1,30 @@
1import { Injectable } from '@angular/core'
2import {
3 ActivatedRouteSnapshot,
4 CanActivateChild,
5 RouterStateSnapshot,
6 CanActivate,
7 Router
8} from '@angular/router'
9
10import { AuthService } from './auth.service'
11
12@Injectable()
13export class LoginGuard implements CanActivate, CanActivateChild {
14
15 constructor (
16 private router: Router,
17 private auth: AuthService
18 ) {}
19
20 canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
21 if (this.auth.isLoggedIn() === true) return true
22
23 this.router.navigate([ '/login' ])
24 return false
25 }
26
27 canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
28 return this.canActivate(route, state)
29 }
30}
diff --git a/client/src/app/core/core.module.ts b/client/src/app/core/core.module.ts
index fd1586f8e..163a6bbde 100644
--- a/client/src/app/core/core.module.ts
+++ b/client/src/app/core/core.module.ts
@@ -7,7 +7,7 @@ import { BrowserAnimationsModule } from '@angular/platform-browser/animations'
7import { SimpleNotificationsModule } from 'angular2-notifications' 7import { SimpleNotificationsModule } from 'angular2-notifications'
8import { ModalModule } from 'ngx-bootstrap/modal' 8import { ModalModule } from 'ngx-bootstrap/modal'
9 9
10import { AuthService } from './auth' 10import { AuthService, LoginGuard } from './auth'
11import { ServerService } from './server' 11import { ServerService } from './server'
12import { ConfirmComponent, ConfirmService } from './confirm' 12import { ConfirmComponent, ConfirmService } from './confirm'
13import { MenuComponent, MenuAdminComponent } from './menu' 13import { MenuComponent, MenuAdminComponent } from './menu'
@@ -41,7 +41,8 @@ import { throwIfAlreadyLoaded } from './module-import-guard'
41 providers: [ 41 providers: [
42 AuthService, 42 AuthService,
43 ConfirmService, 43 ConfirmService,
44 ServerService 44 ServerService,
45 LoginGuard
45 ] 46 ]
46}) 47})
47export class CoreModule { 48export class CoreModule {
diff --git a/client/src/app/core/menu/menu.component.html b/client/src/app/core/menu/menu.component.html
index fb4c4a6a9..ca341a0fd 100644
--- a/client/src/app/core/menu/menu.component.html
+++ b/client/src/app/core/menu/menu.component.html
@@ -33,7 +33,7 @@
33 See videos 33 See videos
34 </a> 34 </a>
35 35
36 <a *ngIf="isLoggedIn" routerLink="/videos/add" routerLinkActive="active"> 36 <a *ngIf="isLoggedIn" routerLink="/videos/upload" routerLinkActive="active">
37 <span class="hidden-xs glyphicon glyphicon-cloud-upload"></span> 37 <span class="hidden-xs glyphicon glyphicon-cloud-upload"></span>
38 Upload a video 38 Upload a video
39 </a> 39 </a>