| author | rougeronj |
| Thu, 11 Jun 2015 16:19:36 +0200 | |
| changeset 172 | ffdfe491869c |
| parent 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 |
|
|
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){ |
|
| 172 | 40 |
$scope.message = ''; |
|
169
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 = { |
| 172 | 43 |
email: '', |
44 |
password: '', |
|
45 |
confirmPassword: '' |
|
|
169
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 { |
| 172 | 60 |
$scope.message = 'Il reste toujours des champs invalides'; |
|
169
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 |
}) |
| 172 | 67 |
.directive('compareTo', function(){ |
|
169
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
68 |
return { |
| 172 | 69 |
require: 'ngModel', |
|
169
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
70 |
scope: { |
| 172 | 71 |
otherModelValue: '=compareTo' |
|
169
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 |
|
| 172 | 75 |
ngModel.$validators.compareTo = function(modelValue) { |
76 |
return modelValue === $scope.otherModelValue; |
|
77 |
}; |
|
|
169
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
78 |
|
| 172 | 79 |
$scope.$watch('otherModelValue', function() { |
80 |
ngModel.$validate(); |
|
81 |
}); |
|
|
169
76fb2dd72ce4
update auth controller to fit to the new server side authentication
rougeronj
parents:
113
diff
changeset
|
82 |
} |
| 172 | 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 |
})(); |