Guest User

Untitled

a guest
Jun 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. angular.module('ModuloDaApp', ['LoginController', 'AdminController', 'UserController', 'ngRoute'])
  2. .run(preAtivador);
  3.  
  4. function preAtivador($rootScope, $location) {
  5. $rootScope.$on('$routeChangeStart', function(event, next, current) {
  6. if ($location.path() == '/login') {
  7. localStorage.clear();
  8. }
  9. if (next.authorize) {
  10. if (!localStorage.token) {
  11. event.preventDefault();
  12. $location.path('#!/login');
  13. }
  14. }
  15. });
  16. }
  17. preAtivador.$inject = ['$rootScope', '$location'];
  18.  
  19. angular.module('ModuloDaApp')
  20. .config(config);
  21.  
  22. function config($routeProvider) {
  23. $routeProvider
  24. .when('/login', {
  25. templateUrl: '../views/login.html',
  26. controller: 'LoginController',
  27. controllerAs: 'Login'
  28. })
  29. .when('/profile/admin', {
  30. templateUrl: '../views-admin/profile.html',
  31. controller: 'AdminController',
  32. controllerAs: 'Admin',
  33. authorize: true
  34. })
  35. .when('/profile/user', {
  36. templateUrl: '../views-user/profile.html',
  37. controller: 'UserController',
  38. controllerAs: 'User',
  39. authorize: true
  40. })
  41. .otherwise({
  42. redirectTo: '/login'
  43. })
  44. // $locationProvider.html5Mode(true);
  45. }
  46. config.$inject = ['$routeProvider']
Add Comment
Please, Sign In to add comment