Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
Prepare for role-based access control of states
Browse files Browse the repository at this point in the history
  • Loading branch information
igorauad committed Jul 24, 2015
1 parent 9fc88e6 commit e21805f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
4 changes: 2 additions & 2 deletions modules/articles/client/config/articles.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ angular.module('articles').config(['$stateProvider',
url: '/create',
templateUrl: 'modules/articles/views/create-article.client.view.html',
data: {
requiresLogin: true
forbiddenRoles: ['guest']
}
}).
state('articles.view', {
Expand All @@ -29,7 +29,7 @@ angular.module('articles').config(['$stateProvider',
url: '/:articleId/edit',
templateUrl: 'modules/articles/views/edit-article.client.view.html',
data: {
requiresLogin: true
forbiddenRoles: ['guest']
}
});
}
Expand Down
17 changes: 10 additions & 7 deletions modules/core/client/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ angular.module(ApplicationConfiguration.applicationModuleName).config(['$locatio
angular.module(ApplicationConfiguration.applicationModuleName).run(function($rootScope, $state, Authentication) {
// Check authentication before changing state
$rootScope.$on('$stateChangeStart', function(event, toState, toParams, fromState, fromParams) {
if (toState.data && toState.data.requiresLogin && Authentication.user === '') {
event.preventDefault();
$state.go('authentication.signin', {}, {
notify: false
}).then(function() {
$rootScope.$broadcast('$stateChangeSuccess', 'authentication.signin', {}, toState, toParams);
});
if (toState.data && toState.data.forbiddenRoles) {
// If access of guest user is forbidden:
if (toState.data.forbiddenRoles.indexOf('guest') !== -1 && Authentication.user === '') {
event.preventDefault();
$state.go('authentication.signin', {}, {
notify: false
}).then(function() {
$rootScope.$broadcast('$stateChangeSuccess', 'authentication.signin', {}, toState, toParams);
});
}
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion modules/users/client/config/users.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ angular.module('users').config(['$stateProvider',
url: '/settings',
templateUrl: 'modules/users/views/settings/settings.client.view.html',
data: {
requiresLogin: true
forbiddenRoles: ['guest']
}
}).
state('settings.profile', {
Expand Down

0 comments on commit e21805f

Please sign in to comment.