You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.7 KiB

  1. 'use strict';
  2. var urlapi = "http://localhost:3000/api/";
  3. //var urlapi = "http://192.168.1.36:3000/api/";
  4. //var urlapi = "http://51.255.193.106:3000/api/";
  5. // Declare app level module which depends on views, and components
  6. angular.module('adminApp', [
  7. 'ngRoute',
  8. 'ngMessages',
  9. 'angularBootstrapMaterial',
  10. 'app.navbar',
  11. 'app.login',
  12. 'app.main',
  13. 'app.user',
  14. 'app.travel',
  15. 'app.network'
  16. ]).
  17. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  18. $locationProvider.hashPrefix('!');
  19. //$routeProvider.otherwise({redirectTo: '/main'});
  20. if((localStorage.getItem('cic_admin_token')))
  21. {
  22. console.log(window.location.hash);
  23. if(window.location.hash==='#!/login')
  24. {
  25. window.location='#!/main';
  26. }
  27. $routeProvider.otherwise({redirectTo: '/main'});
  28. }else{
  29. if(window.location!=='#!/login')
  30. {
  31. console.log('app, user no logged');
  32. localStorage.removeItem('cic_admin_token');
  33. localStorage.removeItem('cic_admin_userdata');
  34. window.location='#!/login';
  35. $routeProvider.otherwise({redirectTo: '/login'});
  36. }
  37. }
  38. }])
  39. .factory('httpInterceptor', function httpInterceptor () {
  40. return {
  41. request: function(config) {
  42. return config;
  43. },
  44. requestError: function(config) {
  45. return config;
  46. },
  47. response: function(res) {
  48. return res;
  49. },
  50. responseError: function(res) {
  51. return res;
  52. }
  53. };
  54. })
  55. .factory('api', function ($http) {
  56. return {
  57. init: function () {
  58. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('cic_admin_token');
  59. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('cic_admin_token');
  60. }
  61. };
  62. })
  63. .run(function (api) {
  64. api.init();
  65. });