Skip to content

Commit cd99e22

Browse files
committed
leaving Polytech
commit/push my changes before leaving polytech.
1 parent ffd0019 commit cd99e22

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed
+39-25
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
1-
zenergyApp.directive('password', function () {
1+
zenergyApp.directive('samepassword', function () {
2+
3+
return {
4+
require: 'ngModel',
5+
link: function (scope, elm, attrs, ctrl) {
6+
ctrl.$validators.samepassword = function (modelValue, viewValue) {
7+
if (ctrl.$isEmpty(modelValue)) {
8+
// consider empty models to be invalid
9+
return false;
10+
}
11+
12+
if (viewvalue != $scope.user) {
13+
// it is valid
14+
return true;
15+
}
16+
17+
// it is invalid
18+
return false;
19+
};
20+
}
21+
}
222

323
});
424

@@ -7,29 +27,23 @@ zenergyApp.controller("registerPageController", ["$scope", "$http", "$window", f
727

828
$scope.user = {mail: '', password: '', passwordBis: '', lastName:'', firstName:'', adr1:'', adr2:'', pc:'', town:'', phone:''};
929
$scope.hasError = false;
10-
$scope.passdiff = false;
30+
31+
$scope.register = function () {
32+
var response = $http({
33+
url: 'api/Account/register',
34+
method: 'POST',
35+
data: { userId: 1, password: CryptoJS.MD5($scope.user.password).toString(), lastName: $scope.user.lastName, firstName: $scope.user.firstName, adr1: $scope.user.adr1, adr2: $scope.user.adr2, pc: $scope.user.pc, town: $scope.user.town, mail: $scope.user.mail, phone: $scope.user.phone },
36+
headers: {
37+
'Content-Type': 'application/json'
38+
}
39+
}).then(function successCallback(response) {
40+
$scope.hasError = false;
41+
window.location.replace("/Login");
42+
}, function errorCallback(response) {
43+
$scope.hasError = true;
44+
$scope.user.mail = '';
45+
$scope.user.password = '';
46+
});
1147

12-
if ($scope.user.password != $scope.user.passwordBis) {
13-
$scope.passdiff = true;
14-
}
15-
else {
16-
$scope.register = function () {
17-
var response = $http({
18-
url: 'api/Account/register',
19-
method: 'POST',
20-
data: { userId: 1, password: CryptoJS.MD5($scope.user.password).toString(), lastName: $scope.user.lastName, firstName: $scope.user.firstName, adr1: $scope.user.adr1, adr2: $scope.user.adr2, pc: $scope.user.pc, town: $scope.user.town, mail: $scope.user.mail, phone: $scope.user.phone },
21-
headers: {
22-
'Content-Type': 'application/json'
23-
}
24-
}).then(function successCallback(response) {
25-
$scope.hasError = false;
26-
window.location.replace("/Login");
27-
}, function errorCallback(response) {
28-
$scope.hasError = true;
29-
$scope.user.mail = '';
30-
$scope.user.password = '';
31-
});
32-
33-
};
34-
}
48+
};
3549
}]);

Diff for: Zenergy/Zenergy/Views/Register/index.cshtml

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@
1010
<h1>Register</h1>
1111
<form ng-submit="register()">
1212

13-
<div class="form-group" ng-class="{ 'has-error': hasError}">
13+
<div class="form-group" >
1414
<input type="email" class="form-control" ng-model="user.mail" placeholder="Email" required>
1515
</div>
1616

17-
<div class="form-group" ng-class="{ 'has-error': passdiff}" password>
18-
<input type="password" class="form-control" ng-model="user.password" placeholder="Password" required>
17+
<div class="form-group">
18+
<input type="password" class="form-control" ng-model="user.password" placeholder="Password" required >
1919
</div>
2020

21-
<div class="form-group" ng-class="{ 'has-error': passdiff}">
22-
<input type="password" class="form-control" ng-model="user.passwordBis" placeholder="Password Confirmation" required>
21+
<div class="form-group" >
22+
<input type="password" class="form-control" ng-model="user.passwordBis" placeholder="Password Confirmation" required samepassword>
2323
</div>
24+
<span ng-show="form.name.$error.samepassword">The password must be equal</span>
2425

2526
<div class="form-group">
2627
<input type="text" class="form-control" ng-model="user.firstName" placeholder="Firstname">
@@ -50,8 +51,6 @@
5051
<input type="text" class="form-control" ng-model="user.phone" placeholder="Phone ">
5152
</div>
5253

53-
<p class="text-danger" ng-if="hasError">Invalid email or password</p>
54-
5554
<input type="submit" id="submit" value="Sign in" class="btn btn-primary" />
5655
</form>
5756
</div>

0 commit comments

Comments
 (0)