diff --git a/packages/app/resource/locales/en_US/translation.json b/packages/app/resource/locales/en_US/translation.json index 5f219aaf5d7..08ffe8daa91 100644 --- a/packages/app/resource/locales/en_US/translation.json +++ b/packages/app/resource/locales/en_US/translation.json @@ -984,6 +984,7 @@ "application_already_installed": "Application already installed.", "email_address_could_not_be_used": "This email address could not be used. (Make sure the allowed email address)", "user_id_is_not_available":"This User ID is not available.", + "username_should_not_be_null":"Username should not be null. Please check Authentication Mechanism Settings on admin page", "email_address_is_already_registered":"This email address is already registered.", "can_not_register_maximum_number_of_users":"Can not register more than the maximum number of users.", "failed_to_register":"Failed to register.", diff --git a/packages/app/resource/locales/ja_JP/translation.json b/packages/app/resource/locales/ja_JP/translation.json index 7c7a45c60cf..5c1ef7ae86c 100644 --- a/packages/app/resource/locales/ja_JP/translation.json +++ b/packages/app/resource/locales/ja_JP/translation.json @@ -977,6 +977,7 @@ "application_already_installed": "アプリケーションのインストールが完了しました。", "email_address_could_not_be_used":"このメールアドレスは使用できません。(許可されたメールアドレスを確認してください。)", "user_id_is_not_available":"このユーザーIDは使用できません。", + "username_should_not_be_null":"Username が null になっています 管理画面の認証機構設定にて設定の確認をしてください", "email_address_is_already_registered":"このメールアドレスは既に登録されています。", "can_not_register_maximum_number_of_users":"ユーザー数が上限を超えたため登録できません。", "failed_to_register":"登録に失敗しました。", diff --git a/packages/app/resource/locales/zh_CN/translation.json b/packages/app/resource/locales/zh_CN/translation.json index 6e394a959fc..68d4a445cab 100644 --- a/packages/app/resource/locales/zh_CN/translation.json +++ b/packages/app/resource/locales/zh_CN/translation.json @@ -986,7 +986,8 @@ "aws_sttings_required": "使用此功能所需的AWS设置。请询问管理员。", "application_already_installed": "应用程序已安装。", "email_address_could_not_be_used": "无法使用此电子邮件地址。(确保允许的电子邮件地址)", - "user_id_is_not_available": "此用户ID不可用。", + "user_id_is_not_available": "此用户ID不可用。", + "username_should_not_be_null":"用户名不应为空。请检查管理页面上的身份验证机制设置", "email_address_is_already_registered": "此电子邮件地址已注册。", "can_not_register_maximum_number_of_users": "注册的用户数不能超过最大值。", "failed_to_register": "注册失败。", diff --git a/packages/app/src/server/models/errors.ts b/packages/app/src/server/models/errors.ts index eab693c2cfe..3019b26644e 100644 --- a/packages/app/src/server/models/errors.ts +++ b/packages/app/src/server/models/errors.ts @@ -10,3 +10,9 @@ export class PathAlreadyExistsError extends ExtensibleCustomError { } } + + +/* +* User Authentication +*/ +export class NullUsernameToBeRegisteredError extends ExtensibleCustomError {} diff --git a/packages/app/src/server/models/external-account.js b/packages/app/src/server/models/external-account.js index c98d0e49d50..828f4197de8 100644 --- a/packages/app/src/server/models/external-account.js +++ b/packages/app/src/server/models/external-account.js @@ -1,5 +1,6 @@ // disable no-return-await for model functions /* eslint-disable no-return-await */ +import { NullUsernameToBeRegisteredError } from '~/server/models/errors'; const debug = require('debug')('growi:models:external-account'); const mongoose = require('mongoose'); @@ -104,6 +105,10 @@ class ExternalAccount { return account; } + if (usernameToBeRegistered == null) { + throw new NullUsernameToBeRegisteredError('username_should_not_be_null'); + } + const User = ExternalAccount.crowi.model('User'); let promise = User.findOne({ username: usernameToBeRegistered }); diff --git a/packages/app/src/server/routes/login-passport.js b/packages/app/src/server/routes/login-passport.js index c84b159f21e..79a6fe557fa 100644 --- a/packages/app/src/server/routes/login-passport.js +++ b/packages/app/src/server/routes/login-passport.js @@ -1,3 +1,4 @@ +import { NullUsernameToBeRegisteredError } from '~/server/models/errors'; import loggerFactory from '~/utils/logger'; /* eslint-disable no-use-before-define */ @@ -109,9 +110,11 @@ module.exports = function(crowi, app) { const attrMapUsername = passportService.getLdapAttrNameMappedToUsername(); const attrMapName = passportService.getLdapAttrNameMappedToName(); const attrMapMail = passportService.getLdapAttrNameMappedToMail(); - const usernameToBeRegistered = ldapAccountInfo[attrMapUsername]; + // const usernameToBeRegistered = ldapAccountInfo[attrMapUsername]; + const usernameToBeRegistered = null; const nameToBeRegistered = ldapAccountInfo[attrMapName]; const mailToBeRegistered = ldapAccountInfo[attrMapMail]; + const userInfo = { id: ldapAccountId, username: usernameToBeRegistered, @@ -578,7 +581,11 @@ module.exports = function(crowi, app) { } catch (err) { /* eslint-disable no-else-return */ - if (err.name === 'DuplicatedUsernameException') { + if (err instanceof NullUsernameToBeRegisteredError) { + req.flash('warningMessage', req.t(`message.${err.message}`)); + return; + } + else if (err.name === 'DuplicatedUsernameException') { if (isSameEmailTreatedAsIdenticalUser || isSameUsernameTreatedAsIdenticalUser) { // associate to existing user debug(`ExternalAccount '${userInfo.username}' will be created and bound to the exisiting User account`);