First commit

This commit is contained in:
2015-09-10 14:02:43 +00:00
commit ab624930df
25 changed files with 933 additions and 0 deletions

33
public/js/app.js Normal file
View File

@@ -0,0 +1,33 @@
(function() {
'use strict';
var HOST = 'http://cloudbudget.pavnay.fr/api';
angular
.module('cloudbudget', ['ngRoute', 'routes', 'ngCookies'])
.constant('apiRoutes', {
'host': HOST,
'port': "80",
'login': HOST + '/users/login',
'register': HOST + '/users',
'unregister': HOST + '/users/'
})
.run(run);
run.$inject = ['$rootScope', '$location', '$cookieStore', '$http', '$filter'];
function run( $rootScope, $location, $cookieStore, $http, $filter) {
$rootScope.globals = $cookieStore.get('globals') || {};
if( $rootScope.globals.user && $rootScope.globals.user.token) {
$http.defaults.headers.common['Authorization'] = 'JWT ' + $rootScope.globals.user.token;
}
$rootScope.$on('$locationChangeStart', function(event, next, current) {
var restrictedPage = ['/login', '/register'].indexOf($location.path()) === -1;
var loggedIn = $rootScope.globals.user;
if( restrictedPage && !loggedIn ) {
$location.path('/login');
}
});
}
})();