diff --git a/es/aspects/token.js b/es/aspects/token.js index 6571114d0..4dbd00063 100644 --- a/es/aspects/token.js +++ b/es/aspects/token.js @@ -11,6 +11,7 @@ import { mergeUser } from './user'; import { cloneDeep } from 'oak-domain/lib/utils/lodash'; import { sendEmail } from '../utils/email'; import { isEmail, isMobile } from 'oak-domain/lib/utils/validator'; +import { getAndCheckPassportByEmail } from '../utils/passport'; async function makeDistinguishException(userId, context, message) { const [user] = await context.select('user', { data: { @@ -468,6 +469,16 @@ export async function loginByMobile(params, context) { if (captchaRow.expired) { throw new OakUserException('验证码已经过期'); } + await context.operate('captcha', { + id: await generateNewIdAsync(), + action: 'update', + data: { + expired: true + }, + filter: { + id: captchaRow.id + } + }, {}); // 到这里说明验证码已经通过 return await setupMobile(mobile, env, context); } @@ -560,49 +571,7 @@ export async function loginByAccount(params, context) { assert(account); const accountType = isEmail(account) ? 'email' : (isMobile(account) ? 'mobile' : 'loginName'); if (accountType === '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 as EmailConfig; - // 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 (account.endsWith(suffix)) { - // isValid = true; - // break; - // } - // } - // if (!isValid) { - // throw new OakUserException('error::user.emailSuffixIsInvalid'); - // } - // } + const { config, emailConfig } = await getAndCheckPassportByEmail(context, account); const existEmail = await context.select('email', { data: { id: 1, @@ -980,46 +949,7 @@ export async function loginByEmail(params, context) { } }; const closeRootMode = context.openRootMode(); - 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('邮箱后缀不符合要求'); - } - } + const { config, emailConfig } = await getAndCheckPassportByEmail(context, email); if (disableRegister) { const [existEmail] = await context.select('email', { data: { @@ -1073,6 +1003,16 @@ export async function bindByMobile(params, context) { throw new OakUserException('验证码已经过期'); } // 到这里说明验证码已经通过 + await context.operate('captcha', { + id: await generateNewIdAsync(), + action: 'update', + data: { + expired: true + }, + filter: { + id: captchaRow.id + } + }, {}); // 检查当前user是否已绑定mobile const [boundMobile] = await context.select('mobile', { data: { @@ -1233,46 +1173,7 @@ export async function bindByEmail(params, context) { } }; const closeRootMode = context.openRootMode(); - 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('邮箱后缀不符合要求'); - } - } + const { config, emailConfig } = await getAndCheckPassportByEmail(context, email); const [otherUserEmail] = await context.select('email', { data: { id: 1, @@ -2054,6 +1955,7 @@ export async function sendCaptchaByMobile({ mobile, env, type: captchaType, }, c const [count1, count2] = await Promise.all([ context.count('captcha', { filter: { + origin: 'mobile', visitorId, $$createAt$$: { $gt: now - 3600 * 1000, @@ -2105,10 +2007,11 @@ export async function sendCaptchaByMobile({ mobile, env, type: captchaType, }, c code = mobile.substring(11 - digit); } else { - code = Math.floor(Math.random() * Math.pow(10, digit)).toString(); - while (code.length < digit) { - code += '0'; - } + // code = Math.floor(Math.random() * Math.pow(10, digit)).toString(); + // while (code.length < digit) { + // code += '0'; + // } + code = Array.from({ length: digit }, () => Math.floor(Math.random() * 10)).join(''); } const id = await generateNewIdAsync(); await context.operate('captcha', { @@ -2137,6 +2040,17 @@ export async function sendCaptchaByMobile({ mobile, env, type: captchaType, }, c closeRootMode(); throw new OakUserException('您的操作太迅捷啦,请稍候再点吧'); } + await context.operate('captcha', { + id: await generateNewIdAsync(), + action: 'update', + data: { + expired: true + }, + filter: { + id: captcha.id + } + }, {}); + code = await getCode(); } else { code = await getCode(); @@ -2168,49 +2082,10 @@ export async function sendCaptchaByEmail({ email, env, type: captchaType, }, con if (type === 'web' || type === 'native') { visitorId = env.visitorId; } - 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 { config, emailConfig } = await getAndCheckPassportByEmail(context, email); const duration = config.codeDuration || 5; const digit = config.digit || 4; const mockSend = config.mockSend; - 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('邮箱后缀不符合要求'); - } - } let emailOptions = { // host: emailConfig.host, // port: emailConfig.port, @@ -2229,6 +2104,7 @@ export async function sendCaptchaByEmail({ email, env, type: captchaType, }, con const [count1, count2] = await Promise.all([ context.count('captcha', { filter: { + origin: 'email', visitorId, $$createAt$$: { $gt: now - 3600 * 1000, @@ -2276,10 +2152,11 @@ export async function sendCaptchaByEmail({ email, env, type: captchaType, }, con }); const getCode = async () => { let code; - code = Math.floor(Math.random() * Math.random() * Math.pow(10, digit)).toString(); - while (code.length < digit) { - code += '0'; - } + // code = Math.floor(Math.random() * Math.random() * Math.pow(10, digit)).toString(); + // while (code.length < digit) { + // code += '0'; + // } + code = Array.from({ length: digit }, () => Math.floor(Math.random() * 10)).join(''); const id = await generateNewIdAsync(); await context.operate('captcha', { id: await generateNewIdAsync(), @@ -2307,6 +2184,17 @@ export async function sendCaptchaByEmail({ email, env, type: captchaType, }, con closeRootMode(); throw new OakUserException('您的操作太迅捷啦,请稍候再点吧'); } + await context.operate('captcha', { + id: await generateNewIdAsync(), + action: 'update', + data: { + expired: true + }, + filter: { + id: captcha.id + } + }, {}); + code = await getCode(); } else { code = await getCode(); diff --git a/es/components/config/application/web/index.js b/es/components/config/application/web/index.js index d8b39a720..5365d6a6e 100644 --- a/es/components/config/application/web/index.js +++ b/es/components/config/application/web/index.js @@ -35,6 +35,24 @@ export default function Web(props) { + + + 网站-微信支付 + +
+ + <> + setValue(`wechatPay.appId`, e.target.value)}/> + + + + <> + setValue(`wechatPay.appSecret`, e.target.value)}/> + + +
+ + location @@ -68,61 +86,5 @@ export default function Web(props) { - - {/* - - 网站-授权方式 - -
- - <> - + setValue(`wechatPay.appId`, e.target.value) + } + /> + + + + <> + + setValue(`wechatPay.appSecret`, e.target.value) + } + /> + + +
+ + location @@ -158,62 +199,6 @@ export default function Web(props: { - - {/* - - 网站-授权方式 - -
- - <> -