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.

77 lines
1.8 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.search',
  14. 'app.travels',
  15. 'app.user',
  16. 'app.travel',
  17. 'app.network',
  18. 'app.userNetwork'
  19. ]).
  20. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  21. $locationProvider.hashPrefix('!');
  22. //$routeProvider.otherwise({redirectTo: '/main'});
  23. if((localStorage.getItem('cic_admin_token')))
  24. {
  25. console.log(window.location.hash);
  26. if(window.location.hash==='#!/login')
  27. {
  28. window.location='#!/main';
  29. }
  30. $routeProvider.otherwise({redirectTo: '/main'});
  31. }else{
  32. if(window.location!=='#!/login')
  33. {
  34. console.log('app, user no logged');
  35. localStorage.removeItem('cic_admin_token');
  36. localStorage.removeItem('cic_admin_userdata');
  37. window.location='#!/login';
  38. $routeProvider.otherwise({redirectTo: '/login'});
  39. }
  40. }
  41. }])
  42. .factory('httpInterceptor', function httpInterceptor () {
  43. return {
  44. request: function(config) {
  45. return config;
  46. },
  47. requestError: function(config) {
  48. return config;
  49. },
  50. response: function(res) {
  51. return res;
  52. },
  53. responseError: function(res) {
  54. return res;
  55. }
  56. };
  57. })
  58. .factory('api', function ($http) {
  59. return {
  60. init: function () {
  61. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('cic_admin_token');
  62. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('cic_admin_token');
  63. }
  64. };
  65. })
  66. .run(function (api) {
  67. api.init();
  68. });