--- a/client/app/auth/auth_controller.js Fri Apr 03 15:05:32 2015 +0200
+++ b/client/app/auth/auth_controller.js Fri Apr 03 15:06:42 2015 +0200
@@ -2,43 +2,51 @@
'use strict';
angular.module('ammicoAuth',['ngRoute'])
- .controller('authCtrl', function($rootScope, $routeParams, $modal){
+ .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, $location, $rootScope){
+ .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();
- $location.path('/books');
+ $modalInstance.close('/books');
});
};
+ $scope.register = function () {
+ $modalInstance.close('/auth/register');
+ };
$scope.cancel = function () {
- $modalInstance.dismiss('cancel');
- $location.path( '/' );
+ $modalInstance.close('/');
};
})
- .controller('authlogoutCtrl', function($modalInstance, $scope, $window, $http, $location, $rootScope){
+ .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();
- $location.path( '/' );
+ $modalInstance.close('/');
};
})
- .controller('authregisterCtrl', function($scope, $modalInstance, $location){
+ .controller('authregisterCtrl', function($scope, $modalInstance, authApi){
$scope.register = function () {
+ authApi.user.save({
+ username: $scope.username,
+ email: $scope.email,
+ password: $scope.password,
+ });
};
$scope.back = function () {
- $modalInstance.close();
- $location.path( '/auth/login' );
+ $modalInstance.close('/auth/login');
};
});
})();