Skip to content

Instantly share code, notes, and snippets.

@pavei
Created May 15, 2014 13:25
Show Gist options
  • Save pavei/e536ccbfa3df653a8c52 to your computer and use it in GitHub Desktop.
Save pavei/e536ccbfa3df653a8c52 to your computer and use it in GitHub Desktop.
config(['$routeProvider', function ($routeProvider) {
$routeProvider.when('/dash', {templateUrl: 'partials/dash.html', controller: 'DashCtrl', requireLogin: true});
$routeProvider.when('/user/list', {templateUrl: 'partials/user.list.html', controller: 'UserListCtrl', requireLogin: true});
$routeProvider.when('/user/new', {templateUrl: 'partials/user.form.html', controller: 'UserNewCtrl', requireLogin: true});
$routeProvider.when('/user/edit', {templateUrl: 'partials/user.form.html', controller: 'UserEditCtrl', requireLogin: true});
$routeProvider.when('/user/login', {templateUrl: 'partials/user.login.form.html', controller: 'UserLoginFormCtrl', requireLogin: false});
$routeProvider.otherwise({redirectTo: '/dash'});
}]).run(function ($rootScope, $location, Services, Enviroment) {
$rootScope.$on('$routeChangeStart', function (event, next, current) {
$rootScope.$broadcast('route');
// if route requires auth and user is not logged in
console.log("routeChangeStart");
if (next.requireLogin && Services.getCurrentUser() == null) {
$location.path('/user/login');
}
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment