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