sou 7 лет назад
Родитель
Сommit
59ca4c613f
1 измененных файлов с 18 добавлено и 0 удалено
  1. 18 0
      lib/routes/login-passport.js

+ 18 - 0
lib/routes/login-passport.js

@@ -259,6 +259,15 @@ module.exports = function(crowi, app) {
         `${response.name.givenName} ${response.name.familyName}`
       )
       .catch((err) => {
+        if (err.name === 'DuplicatedUsernameException') {
+          // get option
+          const isSameUsernameTreatedAsIdenticalUser = Config.isSameUsernameTreatedAsIdenticalUser(config, 'google');
+          if (isSameUsernameTreatedAsIdenticalUser) {
+            // associate to existing user
+            debug(`ExternalAccount '${response.displayName}' will be created and bound to the exisiting User account`);
+            return ExternalAccount.associate('google', response.id, err.user);
+          }
+        }
         throw err;
       })
       .then((externalAccount) => {
@@ -274,6 +283,15 @@ module.exports = function(crowi, app) {
             return loginSuccess(req, res, user);
           }
         });
+      })
+      .catch((err) => {
+        if (err.name === 'DuplicatedUsernameException') {
+          req.flash('isDuplicatedUsernameExceptionOccured', true);
+          return next();
+        }
+        else {
+          return next(err);
+        }
       });
     })(req, res, next);
   };