|
|
@@ -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);
|
|
|
};
|