You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/09/15 04:36:34 UTC
[1/2] ignite git commit: IGNITE-843 Check user e-mail on profile
save. Do not send errors to browser.
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 <ak...@apache.org>
Authored: Tue Sep 15 09:36:45 2015 +0700
Committer: Alexey Kuznetsov <ak...@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)
[2/2] ignite git commit: Merge remote-tracking branch
'origin/ignite-843' into ignite-843
Posted by ak...@apache.org.
Merge remote-tracking branch 'origin/ignite-843' into ignite-843
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/c557f830
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/c557f830
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/c557f830
Branch: refs/heads/ignite-843
Commit: c557f830016c3044a1fa3ab9aaf275f842619edb
Parents: 04400a5 04b37e7
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Tue Sep 15 09:37:16 2015 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Tue Sep 15 09:37:16 2015 +0700
----------------------------------------------------------------------
modules/control-center-web/src/main/js/db.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------