Skip to content

Instantly share code, notes, and snippets.

@quizzicol
Created July 20, 2014 10:07
Show Gist options
  • Save quizzicol/a4f362f24346af57ce4b to your computer and use it in GitHub Desktop.
Save quizzicol/a4f362f24346af57ce4b to your computer and use it in GitHub Desktop.
angular.module('app', ['ngResource', 'ngRoute']);
angular.module('app').config( function( $routeProvider, $locationProvider ) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/',
{
templateUrl: '/partials/main/main',
controller: 'mvMainCtrl'
})
.when('/admin/users',
{
templateUrl: '/partials/admin/user-list',
controller: 'mvUserListCtrl',
resolve: {
auth: function(mvIdentity, $q) {
if (mvIdentity.currentUser && mvIdentity.currentUser.roles.indexOf('admin') > -1) {
return true;
} else {
return $q.reject('not authorized');
}
}
}
});
});
// this will run after the angular app has been fully loaded and configured. It will run after the above code.
angular.module('app').run(function($rootScope, $location) {
$rootScope.$on('$routeChangeError', function(evt, current, previous, rejection) {
if(rejection === 'not authorized') {
$location.path('/');
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment