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 ) {
27
2
28
3
$scope . user = { mail : '' , password : '' , passwordBis : '' , lastName :'' , firstName :'' , adr1 :'' , adr2 :'' , pc :'' , town :'' , phone :'' } ;
29
4
$scope . hasError = false ;
5
+ $scope . passNotMatch = false ;
30
6
31
7
$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
+ {
43
11
$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
+ }
47
19
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
+ }
48
38
} ;
49
39
} ] ) ;
0 commit comments