arnaucube
arnaucube/blockchainIDsystemPublic Self-hosted repository
blockchainIDsystem/clientApp/GUI/app.js
clientApp/GUI/app.jsRaw
 1'use strict';
 2
 3var urlapi = "http://127.0.0.1:3130/";
 4var clientapi = "http://127.0.0.1:4100/";
 5
 6// Declare app level module which depends on views, and components
 7angular.module('app', [
 8    'ngRoute',
 9    'ngMessages',
10    'angularBootstrapMaterial',
11    'ui.bootstrap',
12    'toastr',
13    'app.navbar',
14    'app.main',
15    'app.signup',
16    'app.login'
17]).
18config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
19        $locationProvider.hashPrefix('!');
20
21        if ((localStorage.getItem('blid_token'))) {
22            console.log(window.location.hash);
23            if ((window.location.hash === '#!/login') || (window.location.hash === '#!/signup')) {
24                window.location = '#!/main';
25            }
26
27            $routeProvider.otherwise({
28                redirectTo: '/main'
29            });
30        } else {
31            if ((window.location !== '#!/login') || (window.location !== '#!/signup')) {
32                console.log('app, user no logged');
33
34                localStorage.removeItem('blid_token');
35                localStorage.removeItem('blid_userdata');
36                window.location = '#!/login';
37                $routeProvider.otherwise({
38                    redirectTo: '/login'
39                });
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
61            requestError: function(config) {
62                return config;
63            },
64
65            response: function(res) {
66                return res;
67            },
68
69            responseError: function(res) {
70                return res;
71            }
72        };
73    })
74    .factory('api', function($http) {
75        return {
76            init: function() {
77                /*$http.defaults.headers.common['X-Access-Token'] = localStorage.getItem('block_webapp_token');
78                $http.defaults.headers.post['X-Access-Token'] = localStorage.getItem('block_webapp_token');*/
79            }
80        };
81    })
82    .run(function(api) {
83        api.init();
84    });