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