ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akuznet...@apache.org
Subject [1/2] ignite git commit: IGNITE-843 Check user e-mail on profile save. Do not send errors to browser.
Date Tue, 15 Sep 2015 02:36:34 GMT
Repository: ignite
Updated Branches:
  refs/heads/ignite-843 04b37e782 -> c557f8300


IGNITE-843 Check user e-mail on profile save. Do not send errors to browser.


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

Branch: refs/heads/ignite-843
Commit: 04400a59d50d650edb2a10ebb144075669c58018
Parents: 26e3eef
Author: Alexey Kuznetsov <akuznetsov@apache.org>
Authored: Tue Sep 15 09:36:45 2015 +0700
Committer: Alexey Kuznetsov <akuznetsov@apache.org>
Committed: Tue Sep 15 09:36:45 2015 +0700

----------------------------------------------------------------------
 .../src/main/js/routes/profile.js               | 84 ++++++++++----------
 .../src/main/js/routes/public.js                |  9 ++-
 2 files changed, 48 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/04400a59/modules/control-center-web/src/main/js/routes/profile.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/profile.js b/modules/control-center-web/src/main/js/routes/profile.js
index b772f21..9101742 100644
--- a/modules/control-center-web/src/main/js/routes/profile.js
+++ b/modules/control-center-web/src/main/js/routes/profile.js
@@ -32,28 +32,42 @@ router.get('/', function (req, res) {
     });
 });
 
-function updateUser(user, params) {
-    var updated = false;
-
-    if (params.userName) {
+function _updateUser(res, user, params) {
+    if (params.userName)
         user.username = params.userName;
 
-        updated = true;
-    }
-
-    if (params.email) {
+    if (params.email)
         user.email = params.email;
 
-        updated = true;
-    }
-
-    if (params.token) {
+    if (params.token)
         user.token = params.token;
 
-        updated = true;
-    }
 
-    return updated;
+    if (params.userName || params.email || params.token)
+        user.save(function (err) {
+            if (err)
+                // TODO IGNITE-843 Send error to admin.
+                return res.status(500).send('Failed to update profile!');
+
+            res.json(user);
+        });
+}
+
+function _checkUserEmailAndUpdate(res, user, params) {
+    if (params.email && user.email != params.email) {
+        db.Account.findOne({email: params.email}, function(err, userForEmail) {
+            // TODO send error to admin
+            if (err)
+                return res.status(500).send('Failed to check e-mail!');
+
+            if (userForEmail && userForEmail._id != user._id)
+                return res.status(500).send('User with this e-mail already registered!');
+
+            _updateUser(res, user, params);
+        });
+    }
+    else
+        _updateUser(res, user, params);
 }
 
 /**
@@ -62,41 +76,27 @@ function updateUser(user, params) {
 router.post('/save', function (req, res) {
     var params = req.body;
 
-    if (params.newPassword) {
-        var newPassword = params.newPassword;
+    db.Account.findById(params._id, function (err, user) {
+        if (err)
+        // TODO IGNITE-843 Send error to admin
+            return res.status(500).send('Failed to find user!');
 
-        if (!newPassword || newPassword.length == 0)
-            return res.status(500).send('Wrong value for new password');
+        if (params.newPassword) {
+            var newPassword = params.newPassword;
 
-        db.Account.findById(params._id, function (err, user) {
-            if (err)
-                return res.status(500).send(err);
+            if (!newPassword || newPassword.length == 0)
+                return res.status(500).send('Wrong value for new password!');
 
             user.setPassword(newPassword, function (err, user) {
                 if (err)
                     return res.status(500).send(err.message);
 
-                if (updateUser(user, params))
-                    user.save(function (err) {
-                        if (err)
-                            return res.status(500).send(err.message);
-
-                        res.json(user);
-                    });
+                _checkUserEmailAndUpdate(res, user, params);
             });
-        });
-    }
-    else {
-        var user = {};
-
-        if (updateUser(user, params))
-            db.Account.findByIdAndUpdate(params._id, user, {'new': true}, function (err,
val) {
-                if (err)
-                    return res.status(500).send(err.message);
-
-                res.json(val);
-            })
-    }
+        }
+        else
+            _checkUserEmailAndUpdate(res, user, params);
+    });
 });
 
 module.exports = router;

http://git-wip-us.apache.org/repos/asf/ignite/blob/04400a59/modules/control-center-web/src/main/js/routes/public.js
----------------------------------------------------------------------
diff --git a/modules/control-center-web/src/main/js/routes/public.js b/modules/control-center-web/src/main/js/routes/public.js
index c325bad..3d5cc68 100644
--- a/modules/control-center-web/src/main/js/routes/public.js
+++ b/modules/control-center-web/src/main/js/routes/public.js
@@ -133,13 +133,15 @@ router.post('/password/forgot', function(req, res) {
             return res.status(401).send('No account with that email address exists!');
 
         if (err)
-            return res.status(401).send(err);
+            // TODO IGNITE-843 Send email to admin
+            return res.status(401).send('Failed to reset password!');
 
         user.resetPasswordToken = token;
 
         user.save(function(err) {
             if (err)
-                return res.status(401).send(err);
+            // TODO IGNITE-843 Send email to admin
+            return res.status(401).send('Failed to reset password!');
 
             var mailer  = nodemailer.createTransport(transporter);
 
@@ -174,7 +176,8 @@ router.post('/password/reset', function(req, res) {
             return res.status(500).send('Invalid token for password reset!');
 
         if (err)
-            return res.status(500).send(err);
+            // TODO IGNITE-843 Send email to admin
+            return res.status(500).send('Failed to reset password!');
 
         user.setPassword(req.body.password, function (err, updatedUser) {
             if (err)


Mime
View raw message