Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-843 4113b2a7c -> 79d5f3e3e


IGNITE-843 Added "match" directive and cleanup profile save code.


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/79d5f3e3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/79d5f3e3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/79d5f3e3

Branch: refs/heads/ignite-843
Commit: 79d5f3e3e94750dd41ecd7e0273ac8ddb0ebe830
Parents: 4113b2a
Author: AKuznetsov <akuznet...@gridgain.com>
Authored: Fri Jul 10 17:12:55 2015 +0700
Committer: AKuznetsov <akuznet...@gridgain.com>
Committed: Fri Jul 10 17:12:55 2015 +0700

----------------------------------------------------------------------
 .../nodejs/controllers/common-module.js         | 13 +++++
 .../nodejs/controllers/profile-controller.js    | 28 ++++------
 .../web-control-center/nodejs/routes/profile.js | 56 ++++++++++----------
 .../web-control-center/nodejs/views/login.jade  |  4 +-
 .../nodejs/views/profile.jade                   |  2 +-
 5 files changed, 55 insertions(+), 48 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79d5f3e3/modules/web-control-center/nodejs/controllers/common-module.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/controllers/common-module.js 
b/modules/web-control-center/nodejs/controllers/common-module.js
index 228181a..a76d638 100644
--- a/modules/web-control-center/nodejs/controllers/common-module.js
+++ b/modules/web-control-center/nodejs/controllers/common-module.js
@@ -153,6 +153,19 @@ controlCenterModule.directive('ipaddress', function () {
     }
 });
 
+controlCenterModule.directive('match', function ($parse) {
+    return {
+        require: 'ngModel',
+        link: function (scope, elem, attrs, ctrl) {
+            scope.$watch(function () {
+                return $parse(attrs.match)(scope) === ctrl.$modelValue;
+            }, function (currentValue) {
+                ctrl.$setValidity('mismatch', currentValue);
+            });
+        }
+    };
+});
+
 controlCenterModule.controller('activeLink', [
     '$scope', function ($scope) {
         $scope.isActive = function (path) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79d5f3e3/modules/web-control-center/nodejs/controllers/profile-controller.js
----------------------------------------------------------------------
diff --git 
a/modules/web-control-center/nodejs/controllers/profile-controller.js 
b/modules/web-control-center/nodejs/controllers/profile-controller.js
index 39b3b6e..9c27bc2 100644
--- a/modules/web-control-center/nodejs/controllers/profile-controller.js
+++ b/modules/web-control-center/nodejs/controllers/profile-controller.js
@@ -42,33 +42,27 @@ controlCenterModule.controller('profileController', 
['$scope', '$alert', '$http'
     $scope.saveUser = function() {
         var profile = $scope.profileUser;
 
-        if ($scope.profileUser) {
+        if (profile) {
             var userName = profile.username;
-            var email = profile.email;
-            var newPassword = profile.newPassword;
-            var confirmPassword = profile.confirmPassword;
-
-            var changeUsername = userName && userName.length > 0 && userName 
!= $scope.loggedInUser.username;
-            var changeEmail = email && email.length > 0 && email != 
$scope.loggedInUser.email;
+            var changeUsername = userName != $scope.loggedInUser.username;
 
-            var changePassword = profile.changePassword && newPassword && 
confirmPassword &&
-                 newPassword.length > 0 && confirmPassword.length > 0 && 
newPassword == confirmPassword;
+            var email = profile.email;
+            var changeEmail = email != $scope.loggedInUser.email;
 
-            if (changeUsername || changeEmail || changePassword) {
+            if (changeUsername || changeEmail || profile.changePassword) {
                 $http.post('/profile/saveUser', {
                     _id: profile._id,
-                    changeUsername: changeUsername,
-                    userName: userName,
-                    changeEmail: changeEmail,
-                    email: email,
-                    changePassword: changePassword,
-                    newPassword: newPassword,
-                    confirmPassword: confirmPassword
+                    userName: changeUsername ? userName : undefined,
+                    email: changeEmail ? email : undefined,
+                    newPassword: profile.changePassword ? profile.newPassword 
: undefined
                 }).success(function () {
                     $scope.showInfo('Profile saved.');
 
                     if (changeUsername)
                         $scope.loggedInUser.username = userName;
+
+                    if (changeEmail)
+                        $scope.loggedInUser.email = email;
                 }).error(function (err) {
                     $scope.showError('Failed to save profile: ' + 
commonFunctions.errorMessage(err));
                 });

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79d5f3e3/modules/web-control-center/nodejs/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/routes/profile.js 
b/modules/web-control-center/nodejs/routes/profile.js
index 586df3d..ab9fc9b 100644
--- a/modules/web-control-center/nodejs/routes/profile.js
+++ b/modules/web-control-center/nodejs/routes/profile.js
@@ -29,12 +29,12 @@ router.all('/profile/*', function (req, res, next) {
 });
 
 /**
- * Get list of user accounts.
+ * Get user profile page.
  */
 router.get('/', function (req, res) {
     var user_id = req.currentUserId();
 
-    db.Account.findById(user_id, function (err, user) {
+    db.Account.findById(user_id, function (err) {
         if (err)
             return res.status(500).send(err.message);
 
@@ -42,40 +42,18 @@ router.get('/', function (req, res) {
     });
 });
 
+/**
+ * Save user profile.
+ */
 router.post('/saveUser', function (req, res) {
     var params = req.body;
 
-    if (params.changeUsername || params.changeEmail) {
-        var u = {};
-
-        if (params.changeUsername)
-            u.username = params.userName;
-
-        if (params.changeEmail)
-            u.email = params.email;
-
-        db.Account.findByIdAndUpdate(req.body._id, u, {new: true}, function 
(err, val) {
-            if (err)
-                return res.status(500).send(err);
-
-            res.json(uiUtils.filterUser(val));
-        })
-    }
-
-    if (params.changeEmail) {
-        // TODO
-    }
-
-    if (params.changePassword) {
+    if (params.newPassword) {
         var newPassword = params.newPassword;
-        var confirmPassword = params.confirmPassword;
 
         if (!newPassword || newPassword.length == 0)
             return res.status(500).send('Wrong value for new password');
 
-        if (!confirmPassword || confirmPassword.length == 0 || newPassword != 
confirmPassword)
-            return res.status(500).send('New password does not match 
confirmation');
-
         db.Account.findById(params._id, function (err, user) {
             if (err)
                 return res.status(500).send(err);
@@ -84,6 +62,12 @@ router.post('/saveUser', function (req, res) {
                 if (err)
                     return res.status(500).send(err);
 
+                if (params.userName)
+                    updatedUser.username = params.userName;
+
+                if (params.email)
+                    updatedUser.email = params.email;
+
                 updatedUser.save(function (err) {
                     if (err)
                         return res.status(500).send(err);
@@ -93,6 +77,22 @@ router.post('/saveUser', function (req, res) {
             });
         });
     }
+    else if (params.userName || params.email) {
+        var upd = {};
+
+        if (params.userName)
+            upd.username = params.userName;
+
+        if (params.email)
+            upd.email = params.email;
+
+        db.Account.findByIdAndUpdate(params._id, upd, {new: true}, function 
(err, val) {
+            if (err)
+                return res.status(500).send(err);
+
+            res.json(uiUtils.filterUser(val));
+        })
+    }
 });
 
 module.exports = router;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79d5f3e3/modules/web-control-center/nodejs/views/login.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/login.jade 
b/modules/web-control-center/nodejs/views/login.jade
index 204e763..5bb39dd 100644
--- a/modules/web-control-center/nodejs/views/login.jade
+++ b/modules/web-control-center/nodejs/views/login.jade
@@ -45,8 +45,8 @@ mixin lbl(txt)
                         .details-row(ng-show='action == "register"')
                             +lbl('Confirm:')
                             .col-sm-9.input-tip.has-feedback
-                                input.form-control(type='password', 
ng-model='user_info.confirm', placeholder='Confirm password', required, 
ng-keyup='$event.keyCode == 13 ? auth(action, user_info) : null')
-                                
i.fa.fa-exclamation-triangle.form-control-feedback(ng-show='user_info.password 
!= user_info.confirm' bs-tooltip data-title='Password does not match 
confirmation' type='button')
+                                input.form-control(type='password', 
ng-model='user_info.confirm', match="user_info.password" placeholder='Confirm 
password', required, ng-keyup='$event.keyCode == 13 ? auth(action, user_info) : 
null')
+
             .modal-footer
                 a.show-signup.ng-hide(ng-show='action != "login"', 
ng-click='action = "login";') log in
                 a.show-signup(ng-show="action != 'register'", ng-click='action 
= "register";') sign up

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/79d5f3e3/modules/web-control-center/nodejs/views/profile.jade
----------------------------------------------------------------------
diff --git a/modules/web-control-center/nodejs/views/profile.jade 
b/modules/web-control-center/nodejs/views/profile.jade
index 62f344d..217e892 100644
--- a/modules/web-control-center/nodejs/views/profile.jade
+++ b/modules/web-control-center/nodejs/views/profile.jade
@@ -52,7 +52,7 @@ block container
                             .details-row
                                 +lbl('Confirm:')
                                 .col-sm-4
-                                    input.form-control(type='password', 
ng-model='profileUser.confirmPassword' placeholder='Confirm' 
ng-required='profileUser.changePassword')
+                                    input.form-control(type='password', 
ng-model='profileUser.confirmPassword' match='profileUser.newPassword' 
placeholder='Confirm' ng-required='profileUser.changePassword')
                     .col-sm-12.details-row
                         
button#save-btn.btn.btn-primary(ng-disabled='profileForm.$invalid' 
ng-click='saveUser()') Save
 

Reply via email to