From 9d36063e094d8fca7ff948b06c00127b649ac10c Mon Sep 17 00:00:00 2001 From: yuyx <237899745@qq.com> Date: Fri, 28 Nov 2025 13:50:06 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E9=AA=8C=E8=AF=81?= =?UTF-8?q?=E7=A0=81session=E4=B8=8D=E4=B8=80=E8=87=B4=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题原因: - 验证码图片通过加载,可能不携带session cookie - 导致验证码生成和表单提交使用不同的session 修复方案: - 改用axios请求获取验证码(blob格式) - 确保验证码请求携带withCredentials - 点击"忘记密码"时立即加载验证码 - 切换到注册模式时立即加载验证码 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- frontend/app.html | 2 +- frontend/app.js | 48 +++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/frontend/app.html b/frontend/app.html index 7410130..a62c9bf 100644 --- a/frontend/app.html +++ b/frontend/app.html @@ -1048,7 +1048,7 @@
- + 忘记密码?
diff --git a/frontend/app.js b/frontend/app.js index 4ded9ae..28cefff 100644 --- a/frontend/app.js +++ b/frontend/app.js @@ -516,6 +516,10 @@ handleDragLeave(e) { this.isLogin = !this.isLogin; this.errorMessage = ''; this.successMessage = ''; + // 切换到注册模式时加载验证码 + if (!this.isLogin) { + this.refreshRegisterCaptcha(); + } }, async handleLogin() { @@ -619,23 +623,51 @@ handleDragLeave(e) { }, // 刷新验证码(登录) - refreshCaptcha() { - this.captchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`; + async refreshCaptcha() { + try { + const response = await axios.get(`${this.apiBase}/api/captcha?t=${Date.now()}`, { + responseType: 'blob' + }); + this.captchaUrl = URL.createObjectURL(response.data); + } catch (error) { + console.error('获取验证码失败:', error); + } }, // 刷新注册验证码 - refreshRegisterCaptcha() { - this.registerCaptchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`; + async refreshRegisterCaptcha() { + try { + const response = await axios.get(`${this.apiBase}/api/captcha?t=${Date.now()}`, { + responseType: 'blob' + }); + this.registerCaptchaUrl = URL.createObjectURL(response.data); + } catch (error) { + console.error('获取验证码失败:', error); + } }, // 刷新忘记密码验证码 - refreshForgotPasswordCaptcha() { - this.forgotPasswordCaptchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`; + async refreshForgotPasswordCaptcha() { + try { + const response = await axios.get(`${this.apiBase}/api/captcha?t=${Date.now()}`, { + responseType: 'blob' + }); + this.forgotPasswordCaptchaUrl = URL.createObjectURL(response.data); + } catch (error) { + console.error('获取验证码失败:', error); + } }, // 刷新重发验证邮件验证码 - refreshResendVerifyCaptcha() { - this.resendVerifyCaptchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`; + async refreshResendVerifyCaptcha() { + try { + const response = await axios.get(`${this.apiBase}/api/captcha?t=${Date.now()}`, { + responseType: 'blob' + }); + this.resendVerifyCaptchaUrl = URL.createObjectURL(response.data); + } catch (error) { + console.error('获取验证码失败:', error); + } }, async resendVerification() {