diff --git a/modules/articles/client/config/articles.client.routes.js b/modules/articles/client/config/articles.client.routes.js
index c6890be3ef..ab0337a695 100644
--- a/modules/articles/client/config/articles.client.routes.js
+++ b/modules/articles/client/config/articles.client.routes.js
@@ -8,7 +8,10 @@ angular.module('articles').config(['$stateProvider',
state('articles', {
abstract: true,
url: '/articles',
- template: ''
+ template: '',
+ data: {
+ roles: ['user']
+ }
}).
state('articles.list', {
url: '',
diff --git a/modules/chat/client/config/chat.client.routes.js b/modules/chat/client/config/chat.client.routes.js
index c688ac096f..490a11da88 100644
--- a/modules/chat/client/config/chat.client.routes.js
+++ b/modules/chat/client/config/chat.client.routes.js
@@ -6,7 +6,10 @@ angular.module('chat').config(['$stateProvider',
$stateProvider.
state('chat', {
url: '/chat',
- templateUrl: 'modules/chat/views/chat.client.view.html'
+ templateUrl: 'modules/chat/views/chat.client.view.html',
+ data: {
+ roles: ['user']
+ }
});
}
]);
diff --git a/modules/core/client/app/init.js b/modules/core/client/app/init.js
index 5e144afce5..94b23b80d5 100644
--- a/modules/core/client/app/init.js
+++ b/modules/core/client/app/init.js
@@ -10,6 +10,30 @@ 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.roles && toState.data.roles.length > 0) {
+ var allowed = false;
+ toState.data.roles.forEach(function (role) {
+ if (Authentication.user.roles !== undefined && Authentication.user.roles.indexOf(role) !== -1) {
+ allowed = true;
+ return true;
+ }
+ });
+
+ if (!allowed) {
+ event.preventDefault();
+ $state.go('authentication.signin', {}, {
+ notify: false
+ }).then(function() {
+ $rootScope.$broadcast('$stateChangeSuccess', 'authentication.signin', {}, toState, toParams);
+ });
+ }
+ }
+ });
+});
+
//Then define the init function for starting up the application
angular.element(document).ready(function() {
//Fixing facebook bug with redirect
diff --git a/modules/users/client/config/users.client.routes.js b/modules/users/client/config/users.client.routes.js
index 4c00bc0651..1646d50717 100644
--- a/modules/users/client/config/users.client.routes.js
+++ b/modules/users/client/config/users.client.routes.js
@@ -8,7 +8,10 @@ angular.module('users').config(['$stateProvider',
state('settings', {
abstract: true,
url: '/settings',
- templateUrl: 'modules/users/views/settings/settings.client.view.html'
+ templateUrl: 'modules/users/views/settings/settings.client.view.html',
+ data: {
+ roles: ['user']
+ }
}).
state('settings.profile', {
url: '/profile',
diff --git a/modules/users/client/controllers/settings/settings.client.controller.js b/modules/users/client/controllers/settings/settings.client.controller.js
index 090abc86c4..46c217cb0e 100644
--- a/modules/users/client/controllers/settings/settings.client.controller.js
+++ b/modules/users/client/controllers/settings/settings.client.controller.js
@@ -1,10 +1,7 @@
'use strict';
-angular.module('users').controller('SettingsController', ['$scope', '$location', 'Authentication',
- function($scope, $location, Authentication) {
+angular.module('users').controller('SettingsController', ['$scope', 'Authentication',
+ function($scope, Authentication) {
$scope.user = Authentication.user;
-
- // If user is not signed in then redirect back home
- if (!$scope.user) $location.path('/');
}
]);