| author | rougeronj |
| Thu, 11 Jun 2015 15:36:42 +0200 | |
| changeset 169 | 76fb2dd72ce4 |
| parent 113 | b8400d8efac8 |
| child 172 | ffdfe491869c |
| 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 |
|
|
169
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
4 |
angular.module('ammicoAuth',['ngRoute', 'ngMessages']) |
| 100 | 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){ |
|
|
169
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
40 |
$scope.message = ""; |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
41 |
|
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
42 |
$scope.user = { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
43 |
email: "", |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
44 |
password: "", |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
45 |
confirmPassword: "" |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
46 |
}; |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
47 |
|
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
48 |
$scope.submit = function(isValid) { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
49 |
console.log(isValid); |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
50 |
console.log($scope); |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
51 |
console.log($scope.email); |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
52 |
if (isValid) { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
53 |
authApi.user.save({ |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
54 |
email: $scope.user.email, |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
55 |
password: $scope.user.password, |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
56 |
}, function(){ |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
57 |
$modalInstance.close('/auth/login'); |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
58 |
}); |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
59 |
} else { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
60 |
$scope.message = "Il reste toujours des champs invalides"; |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
61 |
} |
| 100 | 62 |
}; |
63 |
$scope.back = function () { |
|
64 |
$modalInstance.close('/auth/login'); |
|
65 |
}; |
|
|
169
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
66 |
}) |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
67 |
.directive("compareTo", function(){ |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
68 |
return { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
69 |
require: "ngModel", |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
70 |
scope: { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
71 |
otherModelValue: "=compareTo" |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
72 |
}, |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
73 |
link: function($scope, element, attributes, ngModel) { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
74 |
|
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
75 |
ngModel.$validators.compareTo = function(modelValue) { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
76 |
return modelValue == $scope.otherModelValue; |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
77 |
}; |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
78 |
|
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
79 |
$scope.$watch("otherModelValue", function() { |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
80 |
ngModel.$validate(); |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
81 |
}); |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
82 |
} |
|
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
83 |
} |
| 100 | 84 |
}); |
|
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
|
85 |
})(); |