浏览代码

user set password

develop
Robin Thoni 8 年前
父节点
当前提交
8291340ad1

+ 10
- 0
luticate/controllers/directives/dialogokcancel.js 查看文件

14
                     $scope.title = attrs.title;
14
                     $scope.title = attrs.title;
15
                     $scope.model = {};
15
                     $scope.model = {};
16
                     $scope.pending = false;
16
                     $scope.pending = false;
17
+                    $scope.submitted = false;
18
+                    $scope.errorString = "";
17
 
19
 
18
                     $scope.__submit = function()
20
                     $scope.__submit = function()
19
                     {
21
                     {
22
+                        $scope.submitted = true;
23
+                        $scope.errorString = "";
20
                         if ($scope.form.$valid) {
24
                         if ($scope.form.$valid) {
21
                             $scope.pending = true;
25
                             $scope.pending = true;
22
                             $scope.promise = $scope.submitForm();
26
                             $scope.promise = $scope.submitForm();
34
                                         if ($scope.onError) {
38
                                         if ($scope.onError) {
35
                                             $scope.onError(error);
39
                                             $scope.onError(error);
36
                                         }
40
                                         }
41
+                                        if (error.Data) {
42
+                                            $scope.errorString = error.Data;
43
+                                        }
44
+                                        else {
45
+                                            $scope.errorString = error;
46
+                                        }
37
                                         $scope.pending = false;
47
                                         $scope.pending = false;
38
                                     });
48
                                     });
39
                             }
49
                             }

+ 48
- 10
luticate/controllers/modals/useredit.controller.js 查看文件

3
  */
3
  */
4
 
4
 
5
 angular.module('luticate')
5
 angular.module('luticate')
6
-    .controller('UserEditController', ['$scope', 'luticateAuthUsers', 'data',
7
-        function($scope, luticateAuthUsers, data) {
6
+    .controller('UserEditController', ['$scope', 'luticateAuthUsers', 'data', '$q',
7
+        function($scope, luticateAuthUsers, data, $q) {
8
             if (data != null) {
8
             if (data != null) {
9
                 $scope.user = data;
9
                 $scope.user = data;
10
             }
10
             }
13
                     Username: "",
13
                     Username: "",
14
                     Email: "",
14
                     Email: "",
15
                     Firstname: "",
15
                     Firstname: "",
16
-                    Lastname: "",
17
-                    Password: ""
16
+                    Lastname: ""
18
                 };
17
                 };
19
             }
18
             }
19
+            $scope.userPassword = {
20
+                value: "",
21
+                confirm: ""
22
+            };
23
+            $scope.passwordValidation = {
24
+                length: '$value.length >= 5 || $value.length == 0'
25
+            };
26
+            $scope.password2Validation = {
27
+                same_passwords: 'userPassword.value==$value'
28
+            };
29
+
20
             var promiseEditUser = {
30
             var promiseEditUser = {
21
                 id: "promiseEditUser",
31
                 id: "promiseEditUser",
22
                 loaderGroups: ["modal"]
32
                 loaderGroups: ["modal"]
23
             };
33
             };
34
+            var promiseAddUser = {
35
+                id: "promiseAddUser",
36
+                loaderGroups: ["modal"]
37
+            };
38
+            var promiseSetPassword = {
39
+                id: "promiseSetPassword",
40
+                loaderGroups: ["modal"]
41
+            };
42
+
43
+            $scope.onCanceled = function()
44
+            {
45
+                console.log($scope.userPassword);
46
+            };
24
 
47
 
25
             $scope.submitForm = function()
48
             $scope.submitForm = function()
26
             {
49
             {
50
+                console.log($scope.userPassword);
27
                 if ($scope.user.Id != null) {
51
                 if ($scope.user.Id != null) {
28
-                    return luticateAuthUsers.edit({
52
+                    var defer = $q.defer();
53
+                    luticateAuthUsers.edit({
29
                         user_id: $scope.user.Id,
54
                         user_id: $scope.user.Id,
30
                         email: $scope.user.Email,
55
                         email: $scope.user.Email,
31
                         firstname: $scope.user.Firstname,
56
                         firstname: $scope.user.Firstname,
32
                         lastname: $scope.user.Lastname
57
                         lastname: $scope.user.Lastname
33
-                    }, promiseEditUser);
58
+                    }, promiseEditUser)
59
+                        .then(function(data)
60
+                        {
61
+                            console.log($scope.userPassword);
62
+                            if ($scope.userPassword.value != "") {
63
+                                luticateAuthUsers.setPassword({
64
+                                    user_id: $scope.user.Id,
65
+                                    password: $scope.userPassword.value
66
+                                }, promiseSetPassword)
67
+                                    .then(defer.resolve, defer.reject);
68
+                            }
69
+                            else {
70
+                                defer.resolve(data);
71
+                            }
72
+                        }, defer.reject);
73
+                    return defer.promise;
34
                 }
74
                 }
35
                 else {
75
                 else {
36
                     var user = {
76
                     var user = {
38
                         email: $scope.user.Email,
78
                         email: $scope.user.Email,
39
                         firstname: $scope.user.Firstname,
79
                         firstname: $scope.user.Firstname,
40
                         lastname: $scope.user.Lastname,
80
                         lastname: $scope.user.Lastname,
41
-                        password: $scope.user.Password
81
+                        password: $scope.userPassword.value
42
                     };
82
                     };
43
-                    console.log(user);
44
-                    return;
45
-                    return luticateAuthUsers.add(user, promiseEditUser);
83
+                    return luticateAuthUsers.add(user, promiseAddUser);
46
                 }
84
                 }
47
             };
85
             };
48
         }]);
86
         }]);

+ 3
- 4
luticate/views/directives/dialogokcancel.html 查看文件

6
                 <ng-transclude></ng-transclude>
6
                 <ng-transclude></ng-transclude>
7
             </div>
7
             </div>
8
             <div class="clearfix"></div>
8
             <div class="clearfix"></div>
9
-            <!--<span class="error" ng-show="submitted">
10
-                <p class="error" ng-show="{{ e.show }}" ng-repeat="e in submittedErrors" ng-bind-template="{{ e.text | translate }}"></p>
9
+            <span class="error" ng-show="submitted">
10
+                <p class="error">{{ errorString }}</p>
11
             </span>
11
             </span>
12
-            <p class="error" ng-show="{{ e.show }}" ng-repeat="e in alwaysErrors" ng-bind-template="{{ e.text | translate }}"></p>-->
13
         </div>
12
         </div>
14
         <div class="modal-footer">
13
         <div class="modal-footer">
15
             <button type="button" class="btn btn-default" ng-click="__cancel()">Cancel</button>
14
             <button type="button" class="btn btn-default" ng-click="__cancel()">Cancel</button>
16
-            <button type="submit" class="btn btn-default" ng-enabled="!pending" ng-click="submitted = true">OK</button>
15
+            <button type="submit" class="btn btn-default" ng-enabled="!pending">OK</button>
17
         </div>
16
         </div>
18
     </form>
17
     </form>
19
 </div>
18
 </div>

+ 7
- 5
luticate/views/modals/useredit.html 查看文件

26
     <div class="form-group">
26
     <div class="form-group">
27
         <label for="password" class="col-sm-2 control-label">Password</label>
27
         <label for="password" class="col-sm-2 control-label">Password</label>
28
         <div class="col-sm-9">
28
         <div class="col-sm-9">
29
-            <input id="password" class="form-control" type="password" ng-model="user.Password" />
29
+            <input id="password" class="form-control" type="password" ng-model="userPassword.value"
30
+                   name="password" ui-validate="passwordValidation"/>
30
         </div>
31
         </div>
31
         <div class="clearfix"></div>
32
         <div class="clearfix"></div>
32
-        <label for="password" class="col-sm-2 control-label">Confirmation</label>
33
+        <label for="password2" class="col-sm-2 control-label">Confirmation</label>
33
         <div class="col-sm-9">
34
         <div class="col-sm-9">
34
-            <input id="password2" class="form-control" type="password" ng-model="password2"
35
-                   name="password2" ui-validate="{ same_passwords: '$value==user.Password' }"/>
35
+            <input id="password2" class="form-control" type="password" ng-model="userPassword.confirm"
36
+                   name="password2" ui-validate="password2Validation" ui-validate-watch="'userPassword.value'"/>
36
         </div>
37
         </div>
37
         <div class="clearfix"></div>
38
         <div class="clearfix"></div>
38
         <div class="col-sm-offset-2 col-sm-9">
39
         <div class="col-sm-offset-2 col-sm-9">
39
-            <p class="error" ng-show="form.password2.$error.same_passwords && user.Password != ''">Passwords do not match</p>
40
+            <p class="error" ng-show="form.password.$error.length">Passwords is too short</p>
41
+            <p class="error" ng-show="form.password2.$error.same_passwords">Passwords do not match</p>
40
         </div>
42
         </div>
41
     </div>
43
     </div>
42
 </dialog-ok-cancel>
44
 </dialog-ok-cancel>

正在加载...
取消
保存