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.

84 lines
2.5 KiB

  1. 'use strict';
  2. var urlapi = "http://127.0.0.1:3130/";
  3. var clientapi = "http://127.0.0.1:4100/";
  4. // Declare app level module which depends on views, and components
  5. angular.module('app', [
  6. 'ngRoute',
  7. 'ngMessages',
  8. 'angularBootstrapMaterial',
  9. 'ui.bootstrap',
  10. 'toastr',
  11. 'app.navbar',
  12. 'app.main',
  13. 'app.signup',
  14. 'app.login'
  15. ]).
  16. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  17. $locationProvider.hashPrefix('!');
  18. if ((localStorage.getItem('blid_token'))) {
  19. console.log(window.location.hash);
  20. if ((window.location.hash === '#!/login') || (window.location.hash === '#!/signup')) {
  21. window.location = '#!/main';
  22. }
  23. $routeProvider.otherwise({
  24. redirectTo: '/main'
  25. });
  26. } else {
  27. if ((window.location !== '#!/login') || (window.location !== '#!/signup')) {
  28. console.log('app, user no logged');
  29. localStorage.removeItem('blid_token');
  30. localStorage.removeItem('blid_userdata');
  31. window.location = '#!/login';
  32. $routeProvider.otherwise({
  33. redirectTo: '/login'
  34. });
  35. }
  36. }
  37. }])
  38. .config(function(toastrConfig) {
  39. angular.extend(toastrConfig, {
  40. autoDismiss: false,
  41. containerId: 'toast-container',
  42. maxOpened: 0,
  43. newestOnTop: true,
  44. positionClass: 'toast-bottom-right',
  45. preventDuplicates: false,
  46. preventOpenDuplicates: false,
  47. target: 'body'
  48. });
  49. })
  50. .factory('httpInterceptor', function httpInterceptor() {
  51. return {
  52. request: function(config) {
  53. return config;
  54. },
  55. requestError: function(config) {
  56. return config;
  57. },
  58. response: function(res) {
  59. return res;
  60. },
  61. responseError: function(res) {
  62. return res;
  63. }
  64. };
  65. })
  66. .factory('api', function($http) {
  67. return {
  68. init: function() {
  69. /*$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('block_webapp_token');
  70. $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('block_webapp_token');*/
  71. }
  72. };
  73. })
  74. .run(function(api) {
  75. api.init();
  76. });