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.

99 lines
2.5 KiB

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