49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import { assert } from 'oak-domain/lib/utils/assert';
|
|
import { OakUserException } from 'oak-domain/lib/types';
|
|
export async function getAndCheckPassportByEmail(context, email) {
|
|
const application = context.getApplication();
|
|
const { system } = application;
|
|
const [applicationPassport] = await context.select('applicationPassport', {
|
|
data: {
|
|
id: 1,
|
|
passportId: 1,
|
|
passport: {
|
|
id: 1,
|
|
config: 1,
|
|
type: 1,
|
|
},
|
|
applicationId: 1,
|
|
},
|
|
filter: {
|
|
applicationId: application?.id,
|
|
passport: {
|
|
type: 'email',
|
|
},
|
|
},
|
|
}, {
|
|
dontCollect: true,
|
|
});
|
|
assert(applicationPassport?.passport);
|
|
const config = applicationPassport.passport.config;
|
|
const emailConfig = system?.config.Emails?.find((ele) => ele.account === config.account);
|
|
assert(emailConfig);
|
|
const emailSuffixes = config.emailSuffixes;
|
|
// 检查邮箱后缀是否满足配置
|
|
if (emailSuffixes?.length > 0) {
|
|
let isValid = false;
|
|
for (const suffix of emailSuffixes) {
|
|
if (email.endsWith(suffix)) {
|
|
isValid = true;
|
|
break;
|
|
}
|
|
}
|
|
if (!isValid) {
|
|
throw new OakUserException('error::user.emailSuffixIsInvalid');
|
|
}
|
|
}
|
|
return {
|
|
emailConfig,
|
|
config
|
|
};
|
|
}
|