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/auth | |
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/auth')
-rw-r--r-- | client/src/app/core/auth/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/auth/login-guard.service.ts | 30 |
2 files changed, 31 insertions, 0 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 | } | ||