diff -r c7c424e9eed5 -r 537d330ad7f0 client/app/auth/auth_controller.js --- a/client/app/auth/auth_controller.js Wed May 27 19:02:43 2015 +0200 +++ b/client/app/auth/auth_controller.js Wed May 27 19:03:08 2015 +0200 @@ -1,54 +1,53 @@ (function(){ - 'use strict'; + 'use strict'; - angular.module('ammicoAuth',['ngRoute']) - .controller('authCtrl', function($location, $rootScope, $routeParams, $modal){ - $modal.open({ - templateUrl: 'auth/' + $routeParams.action + '_modal.html', - controller: 'auth' + $routeParams.action + 'Ctrl' - }).result.then(function (result) { - $location.path(result); - }, function () { - $location.path('/'); - }); - }) - .controller('authloginCtrl', function($modalInstance, $scope, authApi, $window, $http, $rootScope){ - $scope.login = function(){ - authApi.login.save({username:$scope.username, password:$scope.password}, function(data){ - $rootScope.globals.userLogged = true; - $window.sessionStorage.token = data.token; - $http.defaults.headers.common.Authorization = 'Token ' + $window.sessionStorage.token; - $modalInstance.close('/books'); - }); - }; - $scope.register = function () { - $modalInstance.close('/auth/register'); - }; - $scope.cancel = function () { - $modalInstance.close('/'); - }; - }) - .controller('authlogoutCtrl', function($modalInstance, $scope, $window, $http, $rootScope){ - delete $window.sessionStorage.token; - $rootScope.globals.userLogged = false; - delete $http.defaults.headers.common.Authorization; - - $scope.cancel = function () { - $modalInstance.close('/'); - }; - }) - .controller('authregisterCtrl', function($scope, $modalInstance, authApi){ - $scope.register = function () { - authApi.user.save({ - username: $scope.username, - email: $scope.email, - password: $scope.password, - }, function(){ - $modalInstance.close('/auth/login'); - }); - }; - $scope.back = function () { - $modalInstance.close('/auth/login'); - }; - }); + angular.module('ammicoAuth',['ngRoute']) + .controller('authCtrl', function($location, $rootScope, $routeParams, $modal){ + $modal.open({ + templateUrl: 'auth/' + $routeParams.action + '_modal.html', + controller: 'auth' + $routeParams.action + 'Ctrl' + }).result.then(function (result) { + $location.path(result); + }, function () { + $location.path('/'); + }); + }) + .controller('authloginCtrl', function($modalInstance, $scope, authApi, $window, $http, $rootScope){ + $scope.login = function(){ + authApi.login.save({username:$scope.username, password:$scope.password}, function(data){ + $rootScope.globals.userLogged = true; + localStorage.setItem('token', data.token); + $http.defaults.headers.common.Authorization = 'Token ' + localStorage.getItem('token'); + $modalInstance.close('/books'); + }); + }; + $scope.register = function () { + $modalInstance.close('/auth/register'); + }; + $scope.cancel = function () { + $modalInstance.close('/'); + }; + }) + .controller('authlogoutCtrl', function($modalInstance, $scope, $window, $http, $rootScope){ + localStorage.removeItem('token'); + $rootScope.globals.userLogged = false; + delete $http.defaults.headers.common.Authorization; + $scope.cancel = function () { + $modalInstance.close('/'); + }; + }) + .controller('authregisterCtrl', function($scope, $modalInstance, authApi){ + $scope.register = function () { + authApi.user.save({ + username: $scope.username, + email: $scope.email, + password: $scope.password, + }, function(){ + $modalInstance.close('/auth/login'); + }); + }; + $scope.back = function () { + $modalInstance.close('/auth/login'); + }; + }); })();