fix: 验证码发送失败,使captcha过期
This commit is contained in:
parent
24396a8782
commit
16eb5de960
|
|
@ -2858,9 +2858,11 @@ export async function sendCaptchaByMobile<ED extends EntityDict>(
|
||||||
dontCollect: true,
|
dontCollect: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return code;
|
return {
|
||||||
|
code,
|
||||||
|
captchaId: id
|
||||||
|
};
|
||||||
}
|
}
|
||||||
let code = captcha?.code!;
|
|
||||||
if (captcha) {
|
if (captcha) {
|
||||||
const captchaDuration = process.env.NODE_ENV === 'development' ? 10 * 1000 : 60 * 1000;
|
const captchaDuration = process.env.NODE_ENV === 'development' ? 10 * 1000 : 60 * 1000;
|
||||||
if (now - (captcha.$$createAt$$! as number) < captchaDuration) {
|
if (now - (captcha.$$createAt$$! as number) < captchaDuration) {
|
||||||
|
|
@ -2881,10 +2883,8 @@ export async function sendCaptchaByMobile<ED extends EntityDict>(
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
code = await getCode();
|
|
||||||
} else {
|
|
||||||
code = await getCode();
|
|
||||||
}
|
}
|
||||||
|
const { code, captchaId } = await getCode();
|
||||||
if (mockSend) {
|
if (mockSend) {
|
||||||
closeRootMode();
|
closeRootMode();
|
||||||
return `验证码[${code}]已创建`;
|
return `验证码[${code}]已创建`;
|
||||||
|
|
@ -2904,6 +2904,20 @@ export async function sendCaptchaByMobile<ED extends EntityDict>(
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
return '验证码已发送';
|
return '验证码已发送';
|
||||||
}
|
}
|
||||||
|
await context.operate(
|
||||||
|
'captcha',
|
||||||
|
{
|
||||||
|
id: await generateNewIdAsync(),
|
||||||
|
action: 'update',
|
||||||
|
data: {
|
||||||
|
expired: true
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: captchaId!
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
console.error('短信发送失败,原因:\n', result?.res);
|
console.error('短信发送失败,原因:\n', result?.res);
|
||||||
return '验证码发送失败';
|
return '验证码发送失败';
|
||||||
}
|
}
|
||||||
|
|
@ -3013,10 +3027,6 @@ export async function sendCaptchaByEmail<ED extends EntityDict>(
|
||||||
|
|
||||||
const getCode = async () => {
|
const getCode = async () => {
|
||||||
let code: string;
|
let code: string;
|
||||||
// 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('');
|
code = Array.from({ length: digit }, () => Math.floor(Math.random() * 10)).join('');
|
||||||
const id = await generateNewIdAsync();
|
const id = await generateNewIdAsync();
|
||||||
const applicationId = context.getApplication()?.id!;
|
const applicationId = context.getApplication()?.id!;
|
||||||
|
|
@ -3042,10 +3052,12 @@ export async function sendCaptchaByEmail<ED extends EntityDict>(
|
||||||
dontCollect: true,
|
dontCollect: true,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return code;
|
return {
|
||||||
|
code,
|
||||||
|
captchaId: id
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let code = captcha?.code!;
|
|
||||||
if (captcha) {
|
if (captcha) {
|
||||||
const captchaDuration = process.env.NODE_ENV === 'development' ? 10 * 1000 : 60 * 1000;
|
const captchaDuration = process.env.NODE_ENV === 'development' ? 10 * 1000 : 60 * 1000;
|
||||||
if (now - (captcha.$$createAt$$! as number) < captchaDuration) {
|
if (now - (captcha.$$createAt$$! as number) < captchaDuration) {
|
||||||
|
|
@ -3066,10 +3078,9 @@ export async function sendCaptchaByEmail<ED extends EntityDict>(
|
||||||
},
|
},
|
||||||
{}
|
{}
|
||||||
);
|
);
|
||||||
code = await getCode();
|
|
||||||
} else {
|
|
||||||
code = await getCode();
|
|
||||||
}
|
}
|
||||||
|
const { code, captchaId } = await getCode();
|
||||||
|
|
||||||
if (mockSend) {
|
if (mockSend) {
|
||||||
closeRootMode();
|
closeRootMode();
|
||||||
return `验证码[${code}]已创建`;
|
return `验证码[${code}]已创建`;
|
||||||
|
|
@ -3087,6 +3098,20 @@ export async function sendCaptchaByEmail<ED extends EntityDict>(
|
||||||
if (result.success) {
|
if (result.success) {
|
||||||
return '验证码已发送';
|
return '验证码已发送';
|
||||||
}
|
}
|
||||||
|
await context.operate(
|
||||||
|
'captcha',
|
||||||
|
{
|
||||||
|
id: await generateNewIdAsync(),
|
||||||
|
action: 'update',
|
||||||
|
data: {
|
||||||
|
expired: true
|
||||||
|
},
|
||||||
|
filter: {
|
||||||
|
id: captchaId!
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
console.error('邮件发送失败,原因:\n', result?.error);
|
console.error('邮件发送失败,原因:\n', result?.error);
|
||||||
return '验证码发送失败';
|
return '验证码发送失败';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue