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.

87 lines
2.5 KiB

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