| author | rougeronj |
| Thu, 04 Jun 2015 20:09:20 +0200 | |
| changeset 113 | b8400d8efac8 |
| parent 100 | 537d330ad7f0 |
| child 169 | 76fb2dd72ce4 |
| permissions | -rw-r--r-- |
|
60
7d624c1013a3
add and repair auth module (it was not detected by mercurial anymore due to a cass problem on title)
rougeronj
parents:
diff
changeset
|
1 |
(function(){ |
| 100 | 2 |
'use strict'; |
|
60
7d624c1013a3
add and repair auth module (it was not detected by mercurial anymore due to a cass problem on title)
rougeronj
parents:
diff
changeset
|
3 |
|
| 100 | 4 |
angular.module('ammicoAuth',['ngRoute']) |
5 |
.controller('authCtrl', function($location, $rootScope, $routeParams, $modal){ |
|
6 |
$modal.open({ |
|
7 |
templateUrl: 'auth/' + $routeParams.action + '_modal.html', |
|
8 |
controller: 'auth' + $routeParams.action + 'Ctrl' |
|
9 |
}).result.then(function (result) { |
|
10 |
$location.path(result); |
|
11 |
}, function () { |
|
12 |
$location.path('/'); |
|
13 |
}); |
|
14 |
}) |
|
15 |
.controller('authloginCtrl', function($modalInstance, $scope, authApi, $window, $http, $rootScope){ |
|
16 |
$scope.login = function(){ |
|
| 113 | 17 |
authApi.login.save({email:$scope.email, password:$scope.password}, function(data){ |
| 100 | 18 |
$rootScope.globals.userLogged = true; |
19 |
localStorage.setItem('token', data.token); |
|
20 |
$http.defaults.headers.common.Authorization = 'Token ' + localStorage.getItem('token'); |
|
| 113 | 21 |
$modalInstance.close('/'); |
| 100 | 22 |
}); |
23 |
}; |
|
24 |
$scope.register = function () { |
|
25 |
$modalInstance.close('/auth/register'); |
|
26 |
}; |
|
27 |
$scope.cancel = function () { |
|
28 |
$modalInstance.close('/'); |
|
29 |
}; |
|
30 |
}) |
|
31 |
.controller('authlogoutCtrl', function($modalInstance, $scope, $window, $http, $rootScope){ |
|
32 |
localStorage.removeItem('token'); |
|
33 |
$rootScope.globals.userLogged = false; |
|
34 |
delete $http.defaults.headers.common.Authorization; |
|
35 |
$scope.cancel = function () { |
|
36 |
$modalInstance.close('/'); |
|
37 |
}; |
|
38 |
}) |
|
39 |
.controller('authregisterCtrl', function($scope, $modalInstance, authApi){ |
|
40 |
$scope.register = function () { |
|
41 |
authApi.user.save({ |
|
42 |
email: $scope.email, |
|
43 |
password: $scope.password, |
|
44 |
}, function(){ |
|
45 |
$modalInstance.close('/auth/login'); |
|
46 |
}); |
|
47 |
}; |
|
48 |
$scope.back = function () { |
|
49 |
$modalInstance.close('/auth/login'); |
|
50 |
}; |
|
51 |
}); |
|
|
60
7d624c1013a3
add and repair auth module (it was not detected by mercurial anymore due to a cass problem on title)
rougeronj
parents:
diff
changeset
|
52 |
})(); |