注册前后端连接

main
yuan 3 weeks ago
parent 8db5b1d7e4
commit 83287432b0

@ -48,6 +48,8 @@ public class SysLoginController
@PostMapping("/login") @PostMapping("/login")
public AjaxResult login(@RequestBody LoginBody loginBody) public AjaxResult login(@RequestBody LoginBody loginBody)
{ {
System.out.println("==============="+loginBody.getUuid());
AjaxResult ajax = AjaxResult.success(); AjaxResult ajax = AjaxResult.success();
// 生成令牌 // 生成令牌
String token = loginService.login(loginBody.getUsername(), loginBody.getPassword(), loginBody.getCode(), 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) public String login(String username, String password, String code, String uuid)
{ {
System.out.println("======"+uuid);
// 验证码校验 // 验证码校验
validateCaptcha(username, code, uuid); validateCaptcha(username, code, uuid);
// 登录前置校验 // 登录前置校验

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

Loading…
Cancel
Save