Created
July 20, 2014 10:07
-
-
Save quizzicol/a4f362f24346af57ce4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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