diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-10-10 10:18:25 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-10-10 10:24:02 +0200 |
commit | f47bf2e142b0b22460558e23720f5aed8deb982c (patch) | |
tree | 63a084494585a67e4326bf18c611e108de59aaee | |
parent | 35bf0c83c80f59ca79f4b84fac8700f17adeb22d (diff) | |
download | PeerTube-f47bf2e142b0b22460558e23720f5aed8deb982c.tar.gz PeerTube-f47bf2e142b0b22460558e23720f5aed8deb982c.tar.zst PeerTube-f47bf2e142b0b22460558e23720f5aed8deb982c.zip |
Client: check user is logged in for some pages
10 files changed, 54 insertions, 12 deletions
diff --git a/client/src/app/+admin/admin-guard.service.ts b/client/src/app/+admin/admin-guard.service.ts index a0ad48175..429dc032d 100644 --- a/client/src/app/+admin/admin-guard.service.ts +++ b/client/src/app/+admin/admin-guard.service.ts | |||
@@ -3,7 +3,8 @@ import { | |||
3 | ActivatedRouteSnapshot, | 3 | ActivatedRouteSnapshot, |
4 | CanActivateChild, | 4 | CanActivateChild, |
5 | RouterStateSnapshot, | 5 | RouterStateSnapshot, |
6 | CanActivate | 6 | CanActivate, |
7 | Router | ||
7 | } from '@angular/router' | 8 | } from '@angular/router' |
8 | 9 | ||
9 | import { AuthService } from '../core' | 10 | import { AuthService } from '../core' |
@@ -11,10 +12,16 @@ import { AuthService } from '../core' | |||
11 | @Injectable() | 12 | @Injectable() |
12 | export class AdminGuard implements CanActivate, CanActivateChild { | 13 | export class AdminGuard implements CanActivate, CanActivateChild { |
13 | 14 | ||
14 | constructor (private auth: AuthService) {} | 15 | constructor ( |
16 | private router: Router, | ||
17 | private auth: AuthService | ||
18 | ) {} | ||
15 | 19 | ||
16 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | 20 | canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { |
17 | return this.auth.isAdmin() | 21 | if (this.auth.isAdmin() === true) return true |
22 | |||
23 | this.router.navigate([ '/login' ]) | ||
24 | return false | ||
18 | } | 25 | } |
19 | 26 | ||
20 | canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { | 27 | canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { |
diff --git a/client/src/app/account/account-routing.module.ts b/client/src/app/account/account-routing.module.ts index 029d97788..74d9aa03e 100644 --- a/client/src/app/account/account-routing.module.ts +++ b/client/src/app/account/account-routing.module.ts | |||
@@ -3,13 +3,14 @@ import { RouterModule, Routes } from '@angular/router' | |||
3 | 3 | ||
4 | import { MetaGuard } from '@ngx-meta/core' | 4 | import { MetaGuard } from '@ngx-meta/core' |
5 | 5 | ||
6 | import { LoginGuard } from '../core' | ||
6 | import { AccountComponent } from './account.component' | 7 | import { AccountComponent } from './account.component' |
7 | 8 | ||
8 | const accountRoutes: Routes = [ | 9 | const accountRoutes: Routes = [ |
9 | { | 10 | { |
10 | path: 'account', | 11 | path: 'account', |
11 | component: AccountComponent, | 12 | component: AccountComponent, |
12 | canActivate: [ MetaGuard ], | 13 | canActivate: [ MetaGuard, LoginGuard ], |
13 | data: { | 14 | data: { |
14 | meta: { | 15 | meta: { |
15 | title: 'My account' | 16 | title: 'My account' |
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 @@ | |||
1 | export * from './auth-status.model' | 1 | export * from './auth-status.model' |
2 | export * from './auth-user.model' | 2 | export * from './auth-user.model' |
3 | export * from './auth.service' | 3 | export * from './auth.service' |
4 | export * 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 @@ | |||
1 | import { Injectable } from '@angular/core' | ||
2 | import { | ||
3 | ActivatedRouteSnapshot, | ||
4 | CanActivateChild, | ||
5 | RouterStateSnapshot, | ||
6 | CanActivate, | ||
7 | Router | ||
8 | } from '@angular/router' | ||
9 | |||
10 | import { AuthService } from './auth.service' | ||
11 | |||
12 | @Injectable() | ||
13 | export 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' | |||
7 | import { SimpleNotificationsModule } from 'angular2-notifications' | 7 | import { SimpleNotificationsModule } from 'angular2-notifications' |
8 | import { ModalModule } from 'ngx-bootstrap/modal' | 8 | import { ModalModule } from 'ngx-bootstrap/modal' |
9 | 9 | ||
10 | import { AuthService } from './auth' | 10 | import { AuthService, LoginGuard } from './auth' |
11 | import { ServerService } from './server' | 11 | import { ServerService } from './server' |
12 | import { ConfirmComponent, ConfirmService } from './confirm' | 12 | import { ConfirmComponent, ConfirmService } from './confirm' |
13 | import { MenuComponent, MenuAdminComponent } from './menu' | 13 | import { 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 | }) |
47 | export class CoreModule { | 48 | export 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> |
diff --git a/client/src/app/videos/+video-edit/video-add-routing.module.ts b/client/src/app/videos/+video-edit/video-add-routing.module.ts index 9e8fa4acc..e7a32627c 100644 --- a/client/src/app/videos/+video-edit/video-add-routing.module.ts +++ b/client/src/app/videos/+video-edit/video-add-routing.module.ts | |||
@@ -3,13 +3,14 @@ import { RouterModule, Routes } from '@angular/router' | |||
3 | 3 | ||
4 | import { MetaGuard } from '@ngx-meta/core' | 4 | import { MetaGuard } from '@ngx-meta/core' |
5 | 5 | ||
6 | import { LoginGuard } from '../../core' | ||
6 | import { VideoAddComponent } from './video-add.component' | 7 | import { VideoAddComponent } from './video-add.component' |
7 | 8 | ||
8 | const videoAddRoutes: Routes = [ | 9 | const videoAddRoutes: Routes = [ |
9 | { | 10 | { |
10 | path: '', | 11 | path: '', |
11 | component: VideoAddComponent, | 12 | component: VideoAddComponent, |
12 | canActivateChild: [ MetaGuard ] | 13 | canActivate: [ MetaGuard, LoginGuard ] |
13 | } | 14 | } |
14 | ] | 15 | ] |
15 | 16 | ||
diff --git a/client/src/app/videos/+video-edit/video-update-routing.module.ts b/client/src/app/videos/+video-edit/video-update-routing.module.ts index 1d06a7ac3..22c27a072 100644 --- a/client/src/app/videos/+video-edit/video-update-routing.module.ts +++ b/client/src/app/videos/+video-edit/video-update-routing.module.ts | |||
@@ -3,13 +3,14 @@ import { RouterModule, Routes } from '@angular/router' | |||
3 | 3 | ||
4 | import { MetaGuard } from '@ngx-meta/core' | 4 | import { MetaGuard } from '@ngx-meta/core' |
5 | 5 | ||
6 | import { LoginGuard } from '../../core' | ||
6 | import { VideoUpdateComponent } from './video-update.component' | 7 | import { VideoUpdateComponent } from './video-update.component' |
7 | 8 | ||
8 | const videoUpdateRoutes: Routes = [ | 9 | const videoUpdateRoutes: Routes = [ |
9 | { | 10 | { |
10 | path: '', | 11 | path: '', |
11 | component: VideoUpdateComponent, | 12 | component: VideoUpdateComponent, |
12 | canActivateChild: [ MetaGuard ] | 13 | canActivate: [ MetaGuard, LoginGuard ] |
13 | } | 14 | } |
14 | ] | 15 | ] |
15 | 16 | ||
diff --git a/client/src/app/videos/+video-watch/video-watch-routing.module.ts b/client/src/app/videos/+video-watch/video-watch-routing.module.ts index 97fa5c725..bdd4f945e 100644 --- a/client/src/app/videos/+video-watch/video-watch-routing.module.ts +++ b/client/src/app/videos/+video-watch/video-watch-routing.module.ts | |||
@@ -9,7 +9,7 @@ const videoWatchRoutes: Routes = [ | |||
9 | { | 9 | { |
10 | path: '', | 10 | path: '', |
11 | component: VideoWatchComponent, | 11 | component: VideoWatchComponent, |
12 | canActivateChild: [ MetaGuard ] | 12 | canActivate: [ MetaGuard ] |
13 | } | 13 | } |
14 | ] | 14 | ] |
15 | 15 | ||
diff --git a/client/src/app/videos/videos-routing.module.ts b/client/src/app/videos/videos-routing.module.ts index 225b6b018..d3869748b 100644 --- a/client/src/app/videos/videos-routing.module.ts +++ b/client/src/app/videos/videos-routing.module.ts | |||
@@ -22,11 +22,11 @@ const videosRoutes: Routes = [ | |||
22 | } | 22 | } |
23 | }, | 23 | }, |
24 | { | 24 | { |
25 | path: 'add', | 25 | path: 'upload', |
26 | loadChildren: 'app/videos/+video-edit#VideoAddModule', | 26 | loadChildren: 'app/videos/+video-edit#VideoAddModule', |
27 | data: { | 27 | data: { |
28 | meta: { | 28 | meta: { |
29 | title: 'Add a video' | 29 | title: 'Upload a video' |
30 | } | 30 | } |
31 | } | 31 | } |
32 | }, | 32 | }, |