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

Require login #700

Merged
merged 5 commits into from
Jul 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion modules/articles/client/config/articles.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ angular.module('articles').config(['$stateProvider',
state('articles', {
abstract: true,
url: '/articles',
template: '<ui-view/>'
template: '<ui-view/>',
data: {
roles: ['user']
}
}).
state('articles.list', {
url: '',
Expand Down
5 changes: 4 additions & 1 deletion modules/chat/client/config/chat.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
});
}
]);
24 changes: 24 additions & 0 deletions modules/core/client/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {}, {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this sends the user to the signin route? Shouldn't it take them 'home'?

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
Expand Down
5 changes: 4 additions & 1 deletion modules/users/client/config/users.client.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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('/');
}
]);