Guest User

Untitled

a guest
Oct 21st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. (function () {
  2. 'use strict';
  3.  
  4. angular
  5. .module('main', [
  6. 'ui.router',
  7. 'ui.bootstrap',
  8. 'ngMask',
  9. 'ngCookies',
  10. 'ngRoute',
  11. 'ngDialog',
  12. 'ngAnimate',
  13. 'cr.acl',
  14. 'ui-notification',
  15. 'ngFlash',
  16. 'textAngular',
  17. 'flow',
  18. 'angular-loading-bar',
  19. 'hl.sticky',
  20.  
  21. 'about',
  22. 'speakers',
  23. 'schedule',
  24. 'partner',
  25. 'register',
  26.  
  27. 'admin',
  28.  
  29. 'config'
  30. ])
  31. .config(config)
  32. .run(run);
  33.  
  34. config.$inject = ['$stateProvider', '$urlRouterProvider', 'cfpLoadingBarProvider', 'NotificationProvider'];
  35. function config($stateProvider, $urlRouterProvider, cfpLoadingBarProvider, NotificationProvider) {
  36. cfpLoadingBarProvider.includeSpinner = false;
  37.  
  38. NotificationProvider.setOptions({
  39. startTop: 25,
  40. startRight: 25,
  41. verticalSpacing: 20,
  42. horizontalSpacing: 20,
  43. positionX: 'right',
  44. positionY: 'top'
  45. });
  46.  
  47. $urlRouterProvider.otherwise(function ($injector) {
  48. var $state = $injector.get("$state");
  49. var $location = $injector.get("$location");
  50. var crAcl = $injector.get("crAcl");
  51.  
  52. var state = "";
  53.  
  54. switch (crAcl.getRole()) {
  55. case 'ROLE_ADMIN':
  56. state = 'admin.pages';
  57. break;
  58. default : state = 'main.about';
  59. }
  60.  
  61. if (state) $state.go(state);
  62. else $location.path('/');
  63. });
  64.  
  65. $stateProvider
  66. .state('main', {
  67. url: '/',
  68. abstract: true,
  69. templateUrl: '../views/main.html',
  70. controller: 'GlobalCtrl as vm',
  71. data: {
  72. is_granted: ['ROLE_GUEST']
  73. }
  74. })
  75. .state('blog', {
  76. url: '/blog',
  77. templateUrl: '../blog.html'
  78. })
  79. .state('auth', {
  80. url: '/login',
  81. templateUrl: '../views/auth/login.html',
  82. controller: 'AuthCtrl as auth',
  83. onEnter: ['AuthService', 'crAcl', function(AuthService, crAcl) {
  84. AuthService.clearCredentials();
  85. crAcl.setRole();
  86. }],
  87. data: {
  88. is_granted: ['ROLE_GUEST']
  89. }
  90. });
  91. }
  92.  
  93. run.$inject = ['$rootScope', '$cookieStore', '$state', 'crAcl', '$window'];
  94. function run($rootScope, $cookieStore, $state, crAcl, $window) {
  95. // keep user logged in after page refresh
  96. $rootScope.globals = $cookieStore.get('globals') || {};
  97.  
  98. crAcl
  99. .setInheritanceRoles({
  100. 'ROLE_ADMIN': ['ROLE_ADMIN', 'ROLE_GUEST'],
  101. 'ROLE_GUEST': ['ROLE_GUEST']
  102. });
  103.  
  104. crAcl
  105. .setRedirect('auth');
  106.  
  107. if ($rootScope.globals.currentUser) {
  108. crAcl.setRole('ROLE_ADMIN');
  109. }
  110. else {
  111. crAcl.setRole();
  112. }
  113.  
  114. $rootScope.$on('$stateChangeSuccess', function (event, current, previous) {
  115. $window.document.title = current.title ? current.title + ' - ANGULAR SUMMIT' : 'ANGULAR SUMMIT';
  116. });
  117.  
  118. }
  119.  
  120. })();
Add Comment
Please, Sign In to add comment