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

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
trainerbill committed Jul 24, 2015
1 parent e21805f commit fb71619
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 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: {
forbiddenRoles: ['guest']
roles: ['admin']
}
}).
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: {
forbiddenRoles: ['guest']
roles: ['user']
}
});
}
Expand Down
12 changes: 9 additions & 3 deletions modules/core/client/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ 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.forbiddenRoles) {
// If access of guest user is forbidden:
if (toState.data.forbiddenRoles.indexOf('guest') !== -1 && Authentication.user === '') {
if (toState.data && toState.data.roles && toState.data.roles.length > 0) {
var allowed = false;
toState.data.roles.forEach(function (role) {
if (Authentication.user.roles.indexOf(role) !== -1) {
allowed = true;
}
});

if (!allowed) {
event.preventDefault();
$state.go('authentication.signin', {}, {
notify: false
Expand Down

0 comments on commit fb71619

Please sign in to comment.