You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by an...@apache.org on 2019/01/24 04:29:46 UTC

[ignite] branch master updated: IGNITE-10839 Web Console: Fixed sign in.

This is an automated email from the ASF dual-hosted git repository.

anovikov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new 1a68016  IGNITE-10839 Web Console: Fixed sign in.
1a68016 is described below

commit 1a68016c0d4dbae5c58471d6a81862e490cd38d5
Author: Andrey Novikov <an...@gridgain.com>
AuthorDate: Thu Jan 24 11:27:38 2019 +0700

    IGNITE-10839 Web Console: Fixed sign in.
---
 modules/web-console/backend/app/mongo.js     | 34 ++++++++++++++++------------
 modules/web-console/backend/services/auth.js |  8 ++++++-
 2 files changed, 26 insertions(+), 16 deletions(-)

diff --git a/modules/web-console/backend/app/mongo.js b/modules/web-console/backend/app/mongo.js
index 57171ac..209c11c 100644
--- a/modules/web-console/backend/app/mongo.js
+++ b/modules/web-console/backend/app/mongo.js
@@ -54,6 +54,22 @@ const defineSchema = (mongoose, schemas) => {
     return result;
 };
 
+const upgradeAccounts = (mongo, activation) => {
+    if (activation) {
+        return mongo.Account.find({
+            $or: [{activated: false}, {activated: {$exists: false}}],
+            activationToken: {$exists: false}
+        }, '_id').lean().exec()
+            .then((accounts) => {
+                const conditions = _.map(accounts, (account) => ({session: {$regex: `"${account._id}"`}}));
+
+                return mongoose.connection.db.collection('sessions').deleteMany({$or: conditions});
+            });
+    }
+
+    return mongo.Account.update({activated: false}, {$unset: {activationSentAt: "", activationToken: ""}}, {multi: true}).exec();
+};
+
 module.exports.factory = function(settings, mongoose, schemas) {
     // Use native promises
     mongoose.Promise = global.Promise;
@@ -149,20 +165,8 @@ module.exports.factory = function(settings, mongoose, schemas) {
                 });
         })
         .then((mongo) => {
-            if (settings.activation.enabled) {
-                return mongo.Account.find({
-                    $or: [{activated: false}, {activated: {$exists: false}}],
-                    activationToken: {$exists: false}
-                }, '_id').lean().exec()
-                    .then((accounts) => {
-                        const conditions = _.map(accounts, (account) => ({session: {$regex: `"${account._id}"`}}));
-
-                        return mongoose.connection.db.collection('sessions').deleteMany({$or: conditions});
-                    })
-                    .then(() => mongo)
-                    .catch(() => mongo);
-            }
-
-            return mongo;
+            return upgradeAccounts(mongo, settings.activation.enabled)
+                .then(() => mongo)
+                .catch(() => mongo);
         });
 };
diff --git a/modules/web-console/backend/services/auth.js b/modules/web-console/backend/services/auth.js
index 4679957..c6da86e 100644
--- a/modules/web-console/backend/services/auth.js
+++ b/modules/web-console/backend/services/auth.js
@@ -74,6 +74,9 @@ module.exports.factory = (mongo, settings, errors, utilsService, mailsService) =
                     if (!user)
                         throw new errors.MissingResourceException('Failed to find account with this token! Please check link from email.');
 
+                    if (settings.activation.enabled && !user.activated)
+                        throw new errors.MissingConfirmRegistrationException(user.email);
+
                     return new Promise((resolve, reject) => {
                         user.setPassword(newPassword, (err, _user) => {
                             if (err)
@@ -100,6 +103,9 @@ module.exports.factory = (mongo, settings, errors, utilsService, mailsService) =
                     if (!user)
                         throw new errors.IllegalAccessError('Invalid token for password reset!');
 
+                    if (settings.activation.enabled && !user.activated)
+                        throw new errors.MissingConfirmRegistrationException(user.email);
+
                     return {token, email: user.email};
                 });
         }
@@ -113,7 +119,7 @@ module.exports.factory = (mongo, settings, errors, utilsService, mailsService) =
          */
         static validateActivationToken(user, activationToken) {
             if (user.activated) {
-                if (user.activationToken !== activationToken)
+                if (!_.isEmpty(activationToken) && user.activationToken !== activationToken)
                     return new errors.AuthFailedException('Invalid email or password!');
             }
             else {