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.

91 lines
2.2 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('webapp', [
  7. 'ngRoute',
  8. 'ngMessages',
  9. 'angularBootstrapMaterial',
  10. 'toastr',
  11. 'app.navbar',
  12. 'app.signup',
  13. 'app.login',
  14. 'app.main',
  15. 'app.search',
  16. 'app.travels',
  17. 'app.users',
  18. 'app.user',
  19. 'app.travel',
  20. 'app.newTravel',
  21. 'app.notifications'
  22. ]).
  23. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  24. $locationProvider.hashPrefix('!');
  25. //$routeProvider.otherwise({redirectTo: '/main'});
  26. if((localStorage.getItem('cr_webapp_token')))
  27. {
  28. console.log(window.location.hash);
  29. if((window.location.hash==='#!/login')||(window.location.hash==='#!/signup'))
  30. {
  31. window.location='#!/main';
  32. }
  33. $routeProvider.otherwise({redirectTo: '/main'});
  34. }else{
  35. if((window.location!=='#!/login')||(window.location!=='#!/signup'))
  36. {
  37. console.log('app, user no logged');
  38. localStorage.removeItem('cr_webapp_token');
  39. localStorage.removeItem('cr_webapp_userdata');
  40. window.location='#!/login';
  41. $routeProvider.otherwise({redirectTo: '/login'});
  42. }
  43. }
  44. }])
  45. .config(function(toastrConfig) {
  46. angular.extend(toastrConfig, {
  47. autoDismiss: false,
  48. containerId: 'toast-container',
  49. maxOpened: 0,
  50. newestOnTop: true,
  51. positionClass: 'toast-bottom-right',
  52. preventDuplicates: false,
  53. preventOpenDuplicates: false,
  54. target: 'body'
  55. });
  56. })
  57. .factory('httpInterceptor', function httpInterceptor () {
  58. return {
  59. request: function(config) {
  60. return config;
  61. },
  62. requestError: function(config) {
  63. return config;
  64. },
  65. response: function(res) {
  66. return res;
  67. },
  68. responseError: function(res) {
  69. return res;
  70. }
  71. };
  72. })
  73. .factory('api', function ($http) {
  74. return {
  75. init: function () {
  76. $http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('cr_webapp_token');
  77. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('cr_webapp_token');
  78. }
  79. };
  80. })
  81. .run(function (api) {
  82. api.init();
  83. });