Skip to content

Commit 1b0a19f

Browse files
committed
functional Registration
REgistration feature is functionnal : check if passwords match, miss test if already used mail
1 parent cd99e22 commit 1b0a19f

File tree

2 files changed

+36
-46
lines changed

2 files changed

+36
-46
lines changed
+30-40
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,39 @@
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-
}
22-
23-
});
24-
25-
26-
zenergyApp.controller("registerPageController", ["$scope", "$http", "$window", function ($scope, $http, $window) {
1+
zenergyApp.controller("registerPageController", ["$scope", "$http", "$window", function ($scope, $http, $window) {
272

283
$scope.user = {mail: '', password: '', passwordBis: '', lastName:'', firstName:'', adr1:'', adr2:'', pc:'', town:'', phone:''};
294
$scope.hasError = false;
5+
$scope.passNotMatch = false;
306

317
$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) {
8+
9+
if ($scope.user.password != $scope.user.passwordBis)
10+
{
4311
$scope.hasError = true;
44-
$scope.user.mail = '';
45-
$scope.user.password = '';
46-
});
12+
$scope.passNotMatch = true;
13+
}
14+
else
15+
{
16+
$scope.hasError = false;
17+
$scope.passNotMatch = false;
18+
}
4719

20+
if (!$scope.hasError)
21+
{
22+
var response = $http({
23+
url: '/api/Account/register',
24+
method: 'POST',
25+
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 },
26+
headers: {
27+
'Content-Type': 'application/json'
28+
}
29+
}).then(function successCallback(response) {
30+
$scope.hasError = false;
31+
window.location.replace("/Login");
32+
}, function errorCallback(response) {
33+
$scope.hasError = true;
34+
$scope.user.mail = '';
35+
$scope.user.password = '';
36+
});
37+
}
4838
};
4939
}]);

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h2>Registration</h2>
77
<div class="container " ng-controller="registerPageController">
88
<div class="row">
9-
<div class="col-md-3 col-lg-offset-4">
9+
<div name="formRegistration" class="col-md-3 col-lg-offset-4">
1010
<h1>Register</h1>
1111
<form ng-submit="register()">
1212

@@ -15,13 +15,13 @@
1515
</div>
1616

1717
<div class="form-group">
18-
<input type="password" class="form-control" ng-model="user.password" placeholder="Password" required >
18+
<input type="password" id="password" name="user.password" class="form-control" ng-model="user.password" placeholder="Password" required >
1919
</div>
2020

2121
<div class="form-group" >
22-
<input type="password" class="form-control" ng-model="user.passwordBis" placeholder="Password Confirmation" required samepassword>
22+
<input type="password" id="passwordBis" name="passwordBis" class="form-control" ng-model="user.passwordBis" placeholder="Password Confirmation" required samepassword="password">
2323
</div>
24-
<span ng-show="form.name.$error.samepassword">The password must be equal</span>
24+
<p class="text-danger" ng-if="passNotMatch">Passwords don't match</p>
2525

2626
<div class="form-group">
2727
<input type="text" class="form-control" ng-model="user.firstName" placeholder="Firstname">
@@ -32,11 +32,11 @@
3232
</div>
3333

3434
<div class="form-group">
35-
<input type="text" class="form-control" ng-model="user.adr1" placeholder="Adress">
35+
<input type="text" class="form-control" ng-model="user.adr1" placeholder="Address">
3636
</div>
3737

3838
<div class="form-group">
39-
<input type="text" class="form-control" ng-model="user.adr2" placeholder="Rest of the adress ">
39+
<input type="text" class="form-control" ng-model="user.adr2" placeholder="Rest of the address ">
4040
</div>
4141

4242
<div class="form-group">

0 commit comments

Comments
 (0)