app.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. (function() {
  2. 'use strict';
  3. var HOST = 'http://cloudbudget-febbweiss.c9.io/api';
  4. angular
  5. .module('cloudbudget', ['ngRoute', 'ngAnimate', 'routes', 'angular-growl', 'config', 'ngCookies', 'xeditable'])
  6. .constant('apiRoutes', {
  7. 'host' : HOST,
  8. 'port' : '80',
  9. 'login' : HOST + '/users/login',
  10. 'register' : HOST + '/users',
  11. 'unregister' : HOST + '/users/',
  12. 'accounts' : HOST + '/accounts/'
  13. })
  14. .run(run);
  15. run.$inject = ['$rootScope', '$location', '$cookieStore', '$http', '$filter', 'editableThemes', 'editableOptions'];
  16. function run( $rootScope, $location, $cookieStore, $http, $filter, editableThemes, editableOptions) {
  17. editableThemes.bs3.inputClass = 'input-sm';
  18. editableThemes.bs3.buttonsClass = 'btn-sm';
  19. editableOptions.theme = 'bs3';
  20. $rootScope.globals = $cookieStore.get('globals') || {};
  21. if( $rootScope.globals.user && $rootScope.globals.user.token) {
  22. $http.defaults.headers.common['Authorization'] = 'JWT ' + $rootScope.globals.user.token;
  23. }
  24. $rootScope.$on('$locationChangeStart', function(event, next, current) {
  25. var restrictedPage = ['/login', '/register'].indexOf($location.path()) === -1;
  26. var loggedIn = $rootScope.globals.user;
  27. if( restrictedPage && !loggedIn ) {
  28. $location.path('/login');
  29. }
  30. });
  31. }
  32. })();