排查验证码问题
This commit is contained in:
@@ -37,17 +37,21 @@ export default async function verify(props: VerifyParams): Promise<ApiResponse>
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
console.error('验证码验证失败:', error)
|
||||||
throw new Error('验证码验证失败', {cause: error})
|
throw new Error('验证码验证失败', {cause: error})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function verifyCaptcha(userInput: string): Promise<boolean> {
|
async function verifyCaptcha(userInput: string): Promise<boolean> {
|
||||||
|
console.log("验证验证码:", userInput)
|
||||||
|
|
||||||
const cookieStore = await cookies()
|
const cookieStore = await cookies()
|
||||||
const hash = cookieStore.get('captcha_hash')?.value
|
const hash = cookieStore.get('captcha_hash')?.value
|
||||||
const salt = cookieStore.get('captcha_salt')?.value
|
const salt = cookieStore.get('captcha_salt')?.value
|
||||||
|
|
||||||
// 如果没有找到验证码cookie,验证失败
|
// 如果没有找到验证码cookie,验证失败
|
||||||
if (!hash || !salt) {
|
if (!hash || !salt) {
|
||||||
|
console.log('验证码cookie不存在')
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,6 +63,7 @@ async function verifyCaptcha(userInput: string): Promise<boolean> {
|
|||||||
|
|
||||||
// 比较哈希值
|
// 比较哈希值
|
||||||
const isValid = hash === userInputHash
|
const isValid = hash === userInputHash
|
||||||
|
console.log('验证码验证结果:', isValid, hash, userInputHash)
|
||||||
|
|
||||||
// 验证后删除验证码cookie,防止重复使用
|
// 验证后删除验证码cookie,防止重复使用
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ function generateCaptchaImage(text: string) {
|
|||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
const captchaText = generateCaptchaText()
|
const captchaText = generateCaptchaText()
|
||||||
|
console.log('生成验证码:', captchaText)
|
||||||
|
|
||||||
// 生成验证码图像
|
// 生成验证码图像
|
||||||
const captchaImage = generateCaptchaImage(captchaText)
|
const captchaImage = generateCaptchaImage(captchaText)
|
||||||
|
|||||||
Reference in New Issue
Block a user