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 /client/src/app/core | |
parent | 35bf0c83c80f59ca79f4b84fac8700f17adeb22d (diff) | |
download | PeerTube-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.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/auth/login-guard.service.ts | 30 | ||||
-rw-r--r-- | client/src/app/core/core.module.ts | 5 | ||||
-rw-r--r-- | client/src/app/core/menu/menu.component.html | 2 |
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 @@ | |||
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> |