注册前后端连接

main
yuan 3 weeks ago
parent 8db5b1d7e4
commit 83287432b0

@ -48,6 +48,8 @@ public class SysLoginController
@PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody)
{
System.out.println("==============="+loginBody.getUuid());
AjaxResult ajax = AjaxResult.success();
// 生成令牌
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(),

@ -63,6 +63,7 @@ public class SysLoginService
*/
public String login(String username, String password, String code, String uuid)
{
System.out.println("======"+uuid);
// 验证码校验
validateCaptcha(username, code, uuid);
// 登录前置校验

@ -13,7 +13,7 @@
</div>
<div class="input-group captcha-group">
<i class="fas fa-shield-alt"></i>
<input type="text" v-model="captcha" placeholder="验证码" required />
<input type="text" v-model="code" placeholder="验证码" required />
<!-- 显示验证码图片 -->
<img :src="captchaUrl" @click="refreshCaptcha" alt="验证码" class="captcha-image" style="margin-top: 5px"/>
</div>
@ -33,8 +33,9 @@ export default {
return {
username: '',
password: '',
captcha: '', //
captchaUrl: '' // URL
code: '', //
captchaUrl: '' ,// URL
uuid: ''
};
},
methods: {
@ -45,6 +46,7 @@ export default {
if (data.code === 200) {
// Base64 URL
this.captchaUrl = `data:image/jpeg;base64,${data.img}`;
this.uuid = data.uuid; // uuid
} else {
console.error('获取验证码失败:', data.msg);
}
@ -54,20 +56,35 @@ export default {
});
},
async login() {
try {
const response = await axios.post('http://localhost:8081/login', {
username: this.username,
password: this.password,
captcha: this.captcha //
});
// token
console.log('登录成功', response.data);
} catch (error) {
console.error('登录失败', error);
//
this.refreshCaptcha();
}
},
try {
const response = await axios.post('http://localhost:8081/login', {
username: this.username,
password: this.password,
code: this.code,//
uuid: this.uuid
}, {
headers: {
'Content-Type': 'application/json' // JSON
}
});
console.log('用户名',this.username);
console.log('密码',this.password);
console.log('验证码',this.code);
console.log('uuid',this.uuid);
if (response.data.code === 200) {
console.log('登录成功', response.data);
window.location.href = 'http://localhost:8080'; //
} else {
console.error('登录失败', response.data.msg);
this.refreshCaptcha(); //
}
} catch (error) {
console.error('登录失败', error);
//
this.refreshCaptcha();
}
},
//
refreshCaptcha() {
this.fetchCaptcha();

Loading…
Cancel
Save