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.

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