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.

88 lines
2.1 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.profile'
  14. ]).
  15. config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  16. $locationProvider.hashPrefix('!');
  17. /*$routeProvider.otherwise({
  18. redirectTo: '/main'
  19. });*/
  20. if((localStorage.getItem('dblog_user')))
  21. {
  22. console.log(window.location.hash);
  23. if((window.location.hash==='#!/login')||(window.location.hash==='#!/signup'))
  24. {
  25. window.location='#!/main';
  26. }
  27. $routeProvider.otherwise({redirectTo: '/main'});
  28. }else{
  29. if((window.location!=='#!/login')||(window.location!=='#!/signup')||(window.location!=='#!/main'))
  30. {
  31. console.log('app, user no logged');
  32. localStorage.removeItem('dblog_user');
  33. localStorage.removeItem('dblog_user');
  34. window.location='#!/main';
  35. $routeProvider.otherwise({redirectTo: '/main'});
  36. }
  37. }
  38. }])
  39. .config(function(toastrConfig) {
  40. angular.extend(toastrConfig, {
  41. autoDismiss: false,
  42. containerId: 'toast-container',
  43. maxOpened: 0,
  44. newestOnTop: true,
  45. positionClass: 'toast-bottom-right',
  46. preventDuplicates: false,
  47. preventOpenDuplicates: false,
  48. target: 'body'
  49. });
  50. })
  51. .factory('httpInterceptor', function httpInterceptor() {
  52. return {
  53. request: function(config) {
  54. return config;
  55. },
  56. requestError: function(config) {
  57. return config;
  58. },
  59. response: function(res) {
  60. return res;
  61. },
  62. responseError: function(res) {
  63. return res;
  64. }
  65. };
  66. })
  67. .factory('api', function($http) {
  68. return {
  69. init: function() {
  70. var dblog_user = JSON.parse(localStorage.getItem('dblog_user'));
  71. if (dblog_user) {
  72. $http.defaults.headers.common['Authorization'] = dblog_user.token;
  73. $http.defaults.headers.post['Authorization'] = dblog_user.token;
  74. }
  75. }
  76. };
  77. })
  78. .run(function(api) {
  79. api.init();
  80. });