mirror of https://github.com/certd/certd
修复邮箱注册验证码报错的bug
parent
0c8b8647f3
commit
d32f4fc38e
|
|
@ -56,10 +56,10 @@ function onChange(data: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getCaptchaForm() {
|
async function getCaptchaForm() {
|
||||||
return await captchaRef.value.getCaptchaForm();
|
return await captchaRef.value?.getCaptchaForm();
|
||||||
}
|
}
|
||||||
async function reset() {
|
async function reset() {
|
||||||
await captchaRef.value.reset();
|
await captchaRef.value?.reset();
|
||||||
}
|
}
|
||||||
defineExpose({
|
defineExpose({
|
||||||
getCaptchaForm,
|
getCaptchaForm,
|
||||||
|
|
|
||||||
|
|
@ -53,6 +53,13 @@ function callback(res: { ret: number; ticket: string; randstr: string; errorCode
|
||||||
// res(验证成功) = {ret: 0, ticket: "String", randstr: "String"}
|
// res(验证成功) = {ret: 0, ticket: "String", randstr: "String"}
|
||||||
// res(请求验证码发生错误,验证码自动返回trerror_前缀的容灾票据) = {ret: 0, ticket: "String", randstr: "String", errorCode: Number, errorMessage: "String"}
|
// res(请求验证码发生错误,验证码自动返回trerror_前缀的容灾票据) = {ret: 0, ticket: "String", randstr: "String", errorCode: Number, errorMessage: "String"}
|
||||||
// 此处代码仅为验证结果的展示示例,真实业务接入,建议基于ticket和errorCode情况做不同的业务处理
|
// 此处代码仅为验证结果的展示示例,真实业务接入,建议基于ticket和errorCode情况做不同的业务处理
|
||||||
|
|
||||||
|
if (res.errorCode && res.errorCode > 0) {
|
||||||
|
notification.error({
|
||||||
|
message: `验证码验证失败:${res.errorMessage || res.errorCode}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (res.ret === 0) {
|
if (res.ret === 0) {
|
||||||
emitChange({
|
emitChange({
|
||||||
ticket: res.ticket,
|
ticket: res.ticket,
|
||||||
|
|
@ -116,7 +123,7 @@ function emitChange(value: any) {
|
||||||
emit("change", value);
|
emit("change", value);
|
||||||
}
|
}
|
||||||
function reset() {
|
function reset() {
|
||||||
captchaInstanceRef.value.instance.reset();
|
captchaInstanceRef.value?.instance?.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@
|
||||||
</a-input-password>
|
</a-input-password>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
<a-form-item has-feedback name="imgCode" label="验证码" :rules="rules.imgCode">
|
<a-form-item has-feedback name="captchaForEmail" label="验证码" :rules="rules.captchaForEmail">
|
||||||
<CaptchaInput v-model:model-value="formState.captchaForEmail"></CaptchaInput>
|
<CaptchaInput v-model:model-value="formState.captchaForEmail"></CaptchaInput>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
|
|
||||||
|
|
@ -118,6 +118,7 @@ export default defineComponent({
|
||||||
password: "",
|
password: "",
|
||||||
confirmPassword: "",
|
confirmPassword: "",
|
||||||
captcha: null,
|
captcha: null,
|
||||||
|
captchaForEmail: null,
|
||||||
});
|
});
|
||||||
|
|
||||||
const rules = {
|
const rules = {
|
||||||
|
|
@ -180,10 +181,10 @@ export default defineComponent({
|
||||||
message: "请通过验证码",
|
message: "请通过验证码",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
imgCode: [
|
captchaForEmail: [
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: "请输入验证码",
|
message: "请通过验证码",
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
@ -204,7 +205,7 @@ export default defineComponent({
|
||||||
password: formState.password,
|
password: formState.password,
|
||||||
username: formState.username,
|
username: formState.username,
|
||||||
email: formState.email,
|
email: formState.email,
|
||||||
captcha: formState.captcha,
|
captcha: registerType.value === "email" ? formState.captchaForEmail : formState.captcha,
|
||||||
validateCode: formState.validateCode,
|
validateCode: formState.validateCode,
|
||||||
}) as any
|
}) as any
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -3,57 +3,54 @@ import { ICaptchaAddon } from "../api.js";
|
||||||
import { TencentAccess } from "@certd/plugin-lib";
|
import { TencentAccess } from "@certd/plugin-lib";
|
||||||
|
|
||||||
@IsAddon({
|
@IsAddon({
|
||||||
addonType:"captcha",
|
addonType: "captcha",
|
||||||
name: 'tencent',
|
name: "tencent",
|
||||||
title: '腾讯云验证码',
|
title: "腾讯云验证码",
|
||||||
desc: '',
|
desc: "",
|
||||||
showTest:false,
|
showTest: false,
|
||||||
})
|
})
|
||||||
export class TencentCaptcha extends BaseAddon implements ICaptchaAddon{
|
export class TencentCaptcha extends BaseAddon implements ICaptchaAddon {
|
||||||
|
|
||||||
@AddonInput({
|
@AddonInput({
|
||||||
title: '腾讯云授权',
|
title: "腾讯云授权",
|
||||||
helper: '腾讯云授权',
|
helper: "腾讯云授权",
|
||||||
component: {
|
component: {
|
||||||
name: 'access-selector',
|
name: "access-selector",
|
||||||
vModel:"modelValue",
|
vModel: "modelValue",
|
||||||
from: "sys",
|
from: "sys",
|
||||||
type: 'tencent', //固定授权类型
|
type: "tencent", //固定授权类型
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
accessId :number;
|
accessId: number;
|
||||||
|
|
||||||
@AddonInput({
|
@AddonInput({
|
||||||
title: '验证ID',
|
title: "验证ID",
|
||||||
component: {
|
component: {
|
||||||
name:"a-input-number",
|
name: "a-input-number",
|
||||||
placeholder: 'CaptchaAppId',
|
placeholder: "CaptchaAppId",
|
||||||
},
|
},
|
||||||
helper:"[腾讯云验证码](https://cloud.tencent.com/act/cps/redirect?redirect=37716&cps_key=b3ef73330335d7a6efa4a4bbeeb6b2c9)",
|
helper: "[腾讯云验证码](https://cloud.tencent.com/act/cps/redirect?redirect=37716&cps_key=b3ef73330335d7a6efa4a4bbeeb6b2c9)",
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
captchaAppId:number;
|
captchaAppId: number;
|
||||||
|
|
||||||
@AddonInput({
|
@AddonInput({
|
||||||
title: '验证Key',
|
title: "验证Key",
|
||||||
component: {
|
component: {
|
||||||
placeholder: 'AppSecretKey',
|
placeholder: "AppSecretKey",
|
||||||
},
|
},
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
appSecretKey = '';
|
appSecretKey = "";
|
||||||
|
|
||||||
|
async onValidate(data?: any) {
|
||||||
async onValidate(data?:any) {
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
return false
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const access = await this.getAccess<TencentAccess>(this.accessId);
|
||||||
|
|
||||||
const access = await this.getAccess<TencentAccess>(this.accessId)
|
const sdk = await import("tencentcloud-sdk-nodejs/tencentcloud/services/captcha/v20190722/index.js");
|
||||||
|
|
||||||
const sdk =await import("tencentcloud-sdk-nodejs/tencentcloud/services/captcha/v20190722/index.js");
|
|
||||||
|
|
||||||
const CaptchaClient = sdk.v20190722.Client;
|
const CaptchaClient = sdk.v20190722.Client;
|
||||||
|
|
||||||
|
|
@ -70,18 +67,18 @@ export class TencentCaptcha extends BaseAddon implements ICaptchaAddon{
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// 实例化要请求产品的client对象,clientProfile是可选的
|
// 实例化要请求产品的client对象,clientProfile是可选的
|
||||||
const client = new CaptchaClient(clientConfig);
|
const client = new CaptchaClient(clientConfig);
|
||||||
const params = {
|
const params = {
|
||||||
"CaptchaType": 9, //固定值9
|
CaptchaType: 9, //固定值9
|
||||||
"UserIp": "127.0.0.1",
|
UserIp: "127.0.0.1",
|
||||||
"Ticket": data.ticket,
|
Ticket: data.ticket,
|
||||||
"Randstr": data.randstr,
|
Randstr: data.randstr,
|
||||||
"AppSecretKey": this.appSecretKey,
|
AppSecretKey: this.appSecretKey,
|
||||||
"CaptchaAppId": this.captchaAppId,
|
CaptchaAppId: this.captchaAppId,
|
||||||
};
|
};
|
||||||
const res = await client.DescribeCaptchaResult(params)
|
try {
|
||||||
|
const res = await client.DescribeCaptchaResult(params);
|
||||||
if (res.CaptchaCode == 1) {
|
if (res.CaptchaCode == 1) {
|
||||||
// 验证成功
|
// 验证成功
|
||||||
// verification successful
|
// verification successful
|
||||||
|
|
@ -89,16 +86,21 @@ export class TencentCaptcha extends BaseAddon implements ICaptchaAddon{
|
||||||
} else {
|
} else {
|
||||||
// 验证失败
|
// 验证失败
|
||||||
// verification failed
|
// verification failed
|
||||||
this.logger.error("腾讯云验证码验证失败",res.CaptchaMsg)
|
this.logger.error("腾讯云验证码验证失败", res.CaptchaMsg);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
} catch (err) {
|
||||||
|
if (data.ticket.startsWith("trerror_") && err.message.includes("账户已欠费")) {
|
||||||
|
this.logger.error("腾讯云验证码账户欠费,临时放行:", err.message);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
throw err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async getCaptcha(): Promise<any> {
|
async getCaptcha(): Promise<any> {
|
||||||
return {
|
return {
|
||||||
captchaAppId: this.captchaAppId,
|
captchaAppId: this.captchaAppId,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue