Skip to content

Instantly share code, notes, and snippets.

@mekhami
Created December 5, 2015 02:47
Show Gist options
  • Select an option

  • Save mekhami/359adacab80c6f0d824e to your computer and use it in GitHub Desktop.

Select an option

Save mekhami/359adacab80c6f0d824e to your computer and use it in GitHub Desktop.
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: '../views/codeform.html',
controller: 'MainController',
access: {restricted: false}
}).
when('/confirm/:code', {
templateUrl: '../views/confirm.html',
controller: 'ConfirmController',
access: {restricted: false}
}).
when('/success', {
templateUrl: '../views/success.html',
access: {restricted: false}
}).
when('/error', {
templateUrl: '../views/error.html',
access: {restricted: false}
}).
when('/login', {
templateUrl: '../views/login.html',
controller: 'LoginController',
access: {restricted: false}
}).
when('/logout', {
controller: 'LogoutController',
access: {restricted: false}
}).
when('/admin', {
controller: 'AdminController',
templateUrl: '../views/admin/index.html',
access: {restricted: true}
}).
when('/admin/create', {
controller: 'AdminController',
templateUrl: '../views/admin/create.html',
access: {restricted: true}
});
$locationProvider.html5Mode(true);
}])
myApp.run(function($rootScope, $location, $route, AuthService) {
$rootScope.$on('$routeChangeStart', function(event, next, current) {
if (next.access.restricted && AuthService.isLoggedIn()===false) {
$location.path('/login');
$route.reload();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment