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.

100 lines
2.6 KiB

  1. 'use strict';
  2. var apiurl = "http://127.0.0.1:3000/";
  3. var ipfsurl = "http://127.0.0.1:5001/api/v0/";
  4. angular.module('app', [
  5. 'ngRoute',
  6. 'ngMessages',
  7. 'toastr',
  8. 'chart.js',
  9. 'app.navbar',
  10. 'app.signup',
  11. 'app.login',
  12. 'app.main',
  13. 'app.newmodel',
  14. 'app.users',
  15. 'app.user',
  16. 'app.post',
  17. 'app.write'
  18. ]).
  19. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  20. $locationProvider.hashPrefix('!');
  21. /*$routeProvider.otherwise({
  22. redirectTo: '/main'
  23. });*/
  24. console.log("window", window.location.hash);
  25. if((localStorage.getItem('dblog_user')))
  26. {
  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.hash!=='#!/login')||(window.location.hash!=='#!/signup')||(window.location.hash!=='#!/main')||(window.location.hash!=='#!/user'))
  34. {
  35. console.log('app, user no logged');
  36. localStorage.removeItem('dblog_user');
  37. localStorage.removeItem('dblog_user');
  38. //window.location='#!/main';
  39. $routeProvider.otherwise({redirectTo: '/main'});
  40. }
  41. }
  42. }])
  43. .config(function(toastrConfig) {
  44. angular.extend(toastrConfig, {
  45. autoDismiss: false,
  46. containerId: 'toast-container',
  47. maxOpened: 0,
  48. newestOnTop: true,
  49. positionClass: 'toast-bottom-right',
  50. preventDuplicates: false,
  51. preventOpenDuplicates: false,
  52. target: 'body'
  53. });
  54. })
  55. .factory('httpInterceptor', function httpInterceptor() {
  56. return {
  57. request: function(config) {
  58. return config;
  59. },
  60. requestError: function(config) {
  61. return config;
  62. },
  63. response: function(res) {
  64. return res;
  65. },
  66. responseError: function(res) {
  67. return res;
  68. }
  69. };
  70. })
  71. .factory('api', function($http) {
  72. return {
  73. init: function() {
  74. /*console.log("http", $http.options);
  75. var dblog_user = JSON.parse(localStorage.getItem('dblog_user'));
  76. if (dblog_user) {
  77. $http.defaults.headers.common['Authorization'] = dblog_user.token;
  78. $http.defaults.headers.post['Authorization'] = dblog_user.token;
  79. }*/
  80. }
  81. };
  82. })
  83. .run(function(api) {
  84. api.init();
  85. })
  86. .config(function($sceDelegateProvider) {
  87. $sceDelegateProvider.resourceUrlWhitelist([
  88. // Allow same origin resource loads.
  89. 'self',
  90. // Allow loading from outer templates domain.
  91. 'http://localhost:8080/**'
  92. ]);
  93. });