feat: loginByAccount 只有开启邮箱、手机号再加上密码登录,默认只能账号加密码登录

This commit is contained in:
wkj 2026-01-07 13:40:03 +08:00
parent 0315b11ae2
commit 0ca7f1b020
3 changed files with 15 additions and 3 deletions

View File

@ -592,7 +592,6 @@ export async function loginByAccount(params, context) {
const applicationId = context.getApplicationId();
assert(password);
assert(account);
const accountType = isEmail(account) ? 'email' : (isMobile(account) ? 'mobile' : 'loginName');
const applicationPassports = await context.select('applicationPassport', {
data: {
id: 1,
@ -615,9 +614,14 @@ export async function loginByAccount(params, context) {
}, {
dontCollect: true,
});
// 开启邮箱加密码登录
const allowEmail = !!applicationPassports.find((ele) => ele.passport?.type === 'email');
// 开启手机号加密码登录
const allowSms = !!applicationPassports.find((ele) => ele.passport?.type === 'sms');
// 默认只支持账密登录
const accountType = allowEmail && isEmail(account) ? 'email' : allowSms && (isMobile(account) ? 'mobile' : 'loginName');
if (accountType === 'email') {
// 检查邮箱格式后缀是否合法
const { config, emailConfig } = await getAndCheckPassportByEmail(context, account);
if (!allowEmail) {
throw new OakUserException('暂不支持邮箱登录');

View File

@ -618,7 +618,6 @@ async function loginByAccount(params, context) {
const applicationId = context.getApplicationId();
(0, assert_1.assert)(password);
(0, assert_1.assert)(account);
const accountType = (0, validator_1.isEmail)(account) ? 'email' : ((0, validator_1.isMobile)(account) ? 'mobile' : 'loginName');
const applicationPassports = await context.select('applicationPassport', {
data: {
id: 1,
@ -641,9 +640,14 @@ async function loginByAccount(params, context) {
}, {
dontCollect: true,
});
// 开启邮箱加密码登录
const allowEmail = !!applicationPassports.find((ele) => ele.passport?.type === 'email');
// 开启手机号加密码登录
const allowSms = !!applicationPassports.find((ele) => ele.passport?.type === 'sms');
// 默认只支持账密登录
const accountType = allowEmail && (0, validator_1.isEmail)(account) ? 'email' : allowSms && ((0, validator_1.isMobile)(account) ? 'mobile' : 'loginName');
if (accountType === 'email') {
// 检查邮箱格式后缀是否合法
const { config, emailConfig } = await (0, passport_1.getAndCheckPassportByEmail)(context, account);
if (!allowEmail) {
throw new types_1.OakUserException('暂不支持邮箱登录');

View File

@ -797,7 +797,6 @@ export async function loginByAccount<ED extends EntityDict>(
const applicationId = context.getApplicationId();
assert(password);
assert(account);
const accountType = isEmail(account) ? 'email' : (isMobile(account) ? 'mobile' : 'loginName');
const applicationPassports = await context.select(
'applicationPassport',
{
@ -824,10 +823,15 @@ export async function loginByAccount<ED extends EntityDict>(
dontCollect: true,
}
);
// 开启邮箱加密码登录
const allowEmail = !!applicationPassports.find((ele) => ele.passport?.type === 'email');
// 开启手机号加密码登录
const allowSms = !!applicationPassports.find((ele) => ele.passport?.type === 'sms');
// 默认只支持账密登录
const accountType = allowEmail && isEmail(account) ? 'email' : allowSms && (isMobile(account) ? 'mobile' : 'loginName');
if (accountType === 'email') {
// 检查邮箱格式后缀是否合法
const { config, emailConfig } = await getAndCheckPassportByEmail(context, account);
if (!allowEmail) {
throw new OakUserException('暂不支持邮箱登录');