fix: 修复验证码session不一致的问题
问题原因: - 验证码图片通过<img src>加载,可能不携带session cookie - 导致验证码生成和表单提交使用不同的session 修复方案: - 改用axios请求获取验证码(blob格式) - 确保验证码请求携带withCredentials - 点击"忘记密码"时立即加载验证码 - 切换到注册模式时立即加载验证码 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1048,7 +1048,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div style="text-align: right; margin-bottom: 15px;">
|
<div style="text-align: right; margin-bottom: 15px;">
|
||||||
<a @click="showForgotPasswordModal = true" style="color: #667eea; cursor: pointer; font-size: 14px; text-decoration: none;">
|
<a @click="showForgotPasswordModal = true; refreshForgotPasswordCaptcha()" style="color: #667eea; cursor: pointer; font-size: 14px; text-decoration: none;">
|
||||||
忘记密码?
|
忘记密码?
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -516,6 +516,10 @@ handleDragLeave(e) {
|
|||||||
this.isLogin = !this.isLogin;
|
this.isLogin = !this.isLogin;
|
||||||
this.errorMessage = '';
|
this.errorMessage = '';
|
||||||
this.successMessage = '';
|
this.successMessage = '';
|
||||||
|
// 切换到注册模式时加载验证码
|
||||||
|
if (!this.isLogin) {
|
||||||
|
this.refreshRegisterCaptcha();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async handleLogin() {
|
async handleLogin() {
|
||||||
@@ -619,23 +623,51 @@ handleDragLeave(e) {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// 刷新验证码(登录)
|
// 刷新验证码(登录)
|
||||||
refreshCaptcha() {
|
async refreshCaptcha() {
|
||||||
this.captchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`;
|
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() {
|
async refreshRegisterCaptcha() {
|
||||||
this.registerCaptchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`;
|
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() {
|
async refreshForgotPasswordCaptcha() {
|
||||||
this.forgotPasswordCaptchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`;
|
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() {
|
async refreshResendVerifyCaptcha() {
|
||||||
this.resendVerifyCaptchaUrl = `${this.apiBase}/api/captcha?t=${Date.now()}`;
|
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() {
|
async resendVerification() {
|
||||||
|
|||||||
Reference in New Issue
Block a user