Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('ModuloDaApp', ['LoginController', 'AdminController', 'UserController', 'ngRoute'])
- .run(preAtivador);
- function preAtivador($rootScope, $location) {
- $rootScope.$on('$routeChangeStart', function(event, next, current) {
- if ($location.path() == '/login') {
- localStorage.clear();
- }
- if (next.authorize) {
- if (!localStorage.token) {
- event.preventDefault();
- $location.path('#!/login');
- }
- }
- });
- }
- preAtivador.$inject = ['$rootScope', '$location'];
- angular.module('ModuloDaApp')
- .config(config);
- function config($routeProvider) {
- $routeProvider
- .when('/login', {
- templateUrl: '../views/login.html',
- controller: 'LoginController',
- controllerAs: 'Login'
- })
- .when('/profile/admin', {
- templateUrl: '../views-admin/profile.html',
- controller: 'AdminController',
- controllerAs: 'Admin',
- authorize: true
- })
- .when('/profile/user', {
- templateUrl: '../views-user/profile.html',
- controller: 'UserController',
- controllerAs: 'User',
- authorize: true
- })
- .otherwise({
- redirectTo: '/login'
- })
- // $locationProvider.html5Mode(true);
- }
- config.$inject = ['$routeProvider']
Add Comment
Please, Sign In to add comment