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