blob: 65d0299770fa763832064029eb385a95aad354fd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import { Injectable } from '@angular/core'
import {
ActivatedRouteSnapshot,
CanActivateChild,
RouterStateSnapshot,
CanActivate,
Router
} from '@angular/router'
import { AuthService } from '../auth'
@Injectable()
export class UserRightGuard implements CanActivate, CanActivateChild {
constructor (
private router: Router,
private auth: AuthService
) {}
canActivate (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
const user = this.auth.getUser()
if (user) {
const neededUserRight = route.data.userRight
if (user.hasRight(neededUserRight)) return true
}
this.router.navigate([ '/login' ])
return false
}
canActivateChild (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
return this.canActivate(route, state)
}
}
|