3
I have permission levels for users on my system: admin user and basic user.
I have a page that only administrator users can access. I put an ng-if="isAdmin()" in the menu to hide, if not administrator.
It works correctly, but if by chance the user tries to access the page through the browser URL, he is able to access the page. As I do in Angularjs, do not let access this page if the user is not administrator type?
I’m using ui-router and the Angular version is 1.6 :)
This is my code:
//Rotas
app.config(function($routeProvider) {
$routeProvider.when('/', {
templateUrl : 'home.html',
})
$routeProvider.when('/appointments', {
templateUrl : 'views/appointment/appointment.html',
controller : 'AppointmentController'
})
$routeProvider.when('/patients', {
templateUrl : 'views/patient/patient.html',
controller : 'PatientController'
})
$routeProvider.when('/users', {
templateUrl : 'views/user/user.html',
controller : 'UserController',
})
$routeProvider.when('/services', {
templateUrl : 'views/service/service.html',
controller : 'ServiceController'
})
});
/* Load para pegar as informações do usuário logado */
$scope.getUserData = function(){
OdontoService.load('rest/user/getUserData').then(function (data) {
$scope.userAuthenticated = data.data;
localStorage.setItem('permission', $scope.userAuthenticated.permission);
$scope.isLoading = false;
},function (error){
console.log(error);
});
}
$scope.isAdminUser = function(){
return localStorage.getItem('permission') == 0;
}
Permission 0 means user is administrator.
Post all the code
– novic
You have to put the isAdmin() function to be executed on an initiator, so every time you execute a request, the intercep checks whether it is permissible or not. Put code that we help more.
– Marcos Souza
@Virgilionovic I changed the question, with the code of my project.
– Guilherme Nass
@Marcossouza I changed the question, with the code of my project.
– Guilherme Nass