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
+ }
2
22
3
23
} ) ;
4
24
@@ -7,29 +27,23 @@ zenergyApp.controller("registerPageController", ["$scope", "$http", "$window", f
7
27
8
28
$scope . user = { mail : '' , password : '' , passwordBis : '' , lastName :'' , firstName :'' , adr1 :'' , adr2 :'' , pc :'' , town :'' , phone :'' } ;
9
29
$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
+ } ) ;
11
47
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
+ } ;
35
49
} ] ) ;
0 commit comments