-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from UdL-EPS-SoftArch/route_crud
adding guards to filter user roles on pages
- Loading branch information
Showing
4 changed files
with
63 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import {inject, Injectable} from "@angular/core"; | ||
import {ErrorMessageService} from "../error-handler/error-message.service"; | ||
import {AuthenticationBasicService} from "./authentication-basic.service"; | ||
import {CanActivateFn} from "@angular/router"; | ||
|
||
|
||
@Injectable() | ||
export class PermissionsService{ | ||
constructor(private authentication: AuthenticationBasicService, | ||
private errorMessageService: ErrorMessageService) { | ||
} | ||
|
||
checkLoggedIn(): boolean { | ||
if (!this.authentication.isLoggedIn()) { | ||
this.errorMessageService.showErrorMessage('You should be logged in to perform this action'); | ||
} | ||
return this.authentication.isLoggedIn(); | ||
} | ||
|
||
checkUserAdmin(): boolean { | ||
if (this.checkLoggedIn()){ | ||
if (!this.authentication.isRole('admin')) { | ||
this.errorMessageService.showErrorMessage('You should be role admin to perform this action'); | ||
} | ||
return this.authentication.isRole('admin'); | ||
}else | ||
return false; | ||
} | ||
|
||
checkUserNotAdmin(): boolean { | ||
if (this.checkLoggedIn()){ | ||
if (this.authentication.isRole('admin')) { | ||
this.errorMessageService.showErrorMessage('You should be role user to perform this action'); | ||
} | ||
return !this.authentication.isRole('admin'); | ||
}else | ||
return false; | ||
} | ||
} | ||
|
||
export const CheckLoggedInGuard: CanActivateFn = (route, state) => { | ||
return inject(PermissionsService).checkLoggedIn(); | ||
}; | ||
|
||
export const CheckIsAdminGuard: CanActivateFn = (route, state) => { | ||
return inject(PermissionsService).checkUserAdmin(); | ||
}; | ||
|
||
export const CheckIsNotAdminGuard: CanActivateFn = (route, state) => { | ||
return inject(PermissionsService).checkUserNotAdmin(); | ||
}; |
This file was deleted.
Oops, something went wrong.