mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-28 01:53:53 +08:00
优化登录注册流程,跑通注册登录、接口
This commit is contained in:
+4
-3
@@ -51,7 +51,7 @@ public class LoginController {
|
|||||||
throw new RenException("验证码错误,请重新获取");
|
throw new RenException("验证码错误,请重新获取");
|
||||||
}
|
}
|
||||||
// 按照用户名获取用户
|
// 按照用户名获取用户
|
||||||
SysUserDTO userDTO = sysUserService.getByUsername(login.getMobile());
|
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
||||||
// 判断用户是否存在
|
// 判断用户是否存在
|
||||||
if (userDTO == null) {
|
if (userDTO == null) {
|
||||||
throw new RenException("请检测用户和密码是否输入错误");
|
throw new RenException("请检测用户和密码是否输入错误");
|
||||||
@@ -72,15 +72,16 @@ public class LoginController {
|
|||||||
throw new RenException("验证码错误,请重新获取");
|
throw new RenException("验证码错误,请重新获取");
|
||||||
}
|
}
|
||||||
// 按照用户名获取用户
|
// 按照用户名获取用户
|
||||||
SysUserDTO userDTO = sysUserService.getByUsername(login.getMobile());
|
SysUserDTO userDTO = sysUserService.getByUsername(login.getUsername());
|
||||||
if (userDTO != null){
|
if (userDTO != null){
|
||||||
throw new RenException("此手机号码已经注册过");
|
throw new RenException("此手机号码已经注册过");
|
||||||
}
|
}
|
||||||
userDTO = new SysUserDTO();
|
userDTO = new SysUserDTO();
|
||||||
userDTO.setUsername(login.getMobile());
|
userDTO.setUsername(login.getUsername());
|
||||||
userDTO.setPassword(login.getPassword());
|
userDTO.setPassword(login.getPassword());
|
||||||
sysUserService.save(userDTO);
|
sysUserService.save(userDTO);
|
||||||
return new Result<Void>();
|
return new Result<Void>();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ public class LoginDTO implements Serializable {
|
|||||||
|
|
||||||
@Schema(description = "手机号码")
|
@Schema(description = "手机号码")
|
||||||
@NotBlank(message = "{sysuser.username.require}")
|
@NotBlank(message = "{sysuser.username.require}")
|
||||||
private String mobile;
|
private String username;
|
||||||
|
|
||||||
@Schema(description = "密码")
|
@Schema(description = "密码")
|
||||||
@NotBlank(message = "{sysuser.password.require}")
|
@NotBlank(message = "{sysuser.password.require}")
|
||||||
|
|||||||
Generated
+6
-1
@@ -14,7 +14,8 @@
|
|||||||
"vue": "^2.6.14",
|
"vue": "^2.6.14",
|
||||||
"vue-axios": "^3.5.2",
|
"vue-axios": "^3.5.2",
|
||||||
"vue-router": "^3.6.5",
|
"vue-router": "^3.6.5",
|
||||||
"vuex": "^3.6.2"
|
"vuex": "^3.6.2",
|
||||||
|
"xiaozhi": "file:"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vue/cli-plugin-router": "~5.0.0",
|
"@vue/cli-plugin-router": "~5.0.0",
|
||||||
@@ -9157,6 +9158,10 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/xiaozhi": {
|
||||||
|
"resolved": "",
|
||||||
|
"link": true
|
||||||
|
},
|
||||||
"node_modules/y18n": {
|
"node_modules/y18n": {
|
||||||
"version": "5.0.8",
|
"version": "5.0.8",
|
||||||
"resolved": "https://registry.npmmirror.com/y18n/-/y18n-5.0.8.tgz",
|
"resolved": "https://registry.npmmirror.com/y18n/-/y18n-5.0.8.tgz",
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import user from './module/user.js'
|
|||||||
* 如果你想调用8002端口,就用'/xiaozhi-esp32-api/api/v1',请与vue.config.js的devServer配置相结合,方便跨域请求
|
* 如果你想调用8002端口,就用'/xiaozhi-esp32-api/api/v1',请与vue.config.js的devServer配置相结合,方便跨域请求
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
const DEV_API_SERVICE = 'https://apifoxmock.com/m1/5931378-5618560-default'
|
// const DEV_API_SERVICE = 'https://apifoxmock.com/m1/5931378-5618560-default'
|
||||||
// 8002开发完成完成后使用这个
|
// 8002开发完成完成后使用这个
|
||||||
// const DEV_API_SERVICE = '/xiaozhi-esp32-api/api/v1'
|
const DEV_API_SERVICE = '/xiaozhi-esp32-api'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据开发环境返回接口url
|
* 根据开发环境返回接口url
|
||||||
|
|||||||
@@ -75,7 +75,8 @@ export default {
|
|||||||
form: {
|
form: {
|
||||||
username: '',
|
username: '',
|
||||||
password: '',
|
password: '',
|
||||||
captcha: ''
|
captcha: '',
|
||||||
|
captchaId: ''
|
||||||
},
|
},
|
||||||
captchaUuid: '',
|
captchaUuid: '',
|
||||||
captchaUrl: ''
|
captchaUrl: ''
|
||||||
@@ -114,6 +115,7 @@ export default {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.form.captchaId = this.captchaUuid
|
||||||
Api.user.login(this.form, ({data}) => {
|
Api.user.login(this.form, ({data}) => {
|
||||||
showSuccess('登陆成功!')
|
showSuccess('登陆成功!')
|
||||||
goToPage('/home')
|
goToPage('/home')
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ export default {
|
|||||||
password: '',
|
password: '',
|
||||||
confirmPassword: '',
|
confirmPassword: '',
|
||||||
captcha: '',
|
captcha: '',
|
||||||
uuid: ''
|
captchaId: ''
|
||||||
},
|
},
|
||||||
captchaUrl: ''
|
captchaUrl: ''
|
||||||
}
|
}
|
||||||
@@ -106,8 +106,8 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
// 复用验证码获取方法
|
// 复用验证码获取方法
|
||||||
fetchCaptcha() {
|
fetchCaptcha() {
|
||||||
this.form.uuid = Date.now().toString()
|
this.form.captchaId = Date.now().toString()
|
||||||
Api.user.getCaptcha(this.form.uuid, (res) => {
|
Api.user.getCaptcha(this.form.captchaId, (res) => {
|
||||||
if (res.status === 200) {
|
if (res.status === 200) {
|
||||||
const blob = new Blob([res.data], {type: res.data.type});
|
const blob = new Blob([res.data], {type: res.data.type});
|
||||||
this.captchaUrl = URL.createObjectURL(blob);
|
this.captchaUrl = URL.createObjectURL(blob);
|
||||||
|
|||||||
@@ -1,14 +1,23 @@
|
|||||||
const { defineConfig } = require('@vue/cli-service');
|
const { defineConfig } = require('@vue/cli-service');
|
||||||
const dotenv = require('dotenv');
|
const dotenv = require('dotenv');
|
||||||
|
|
||||||
|
// 确保加载 .env 文件
|
||||||
dotenv.config();
|
dotenv.config();
|
||||||
|
|
||||||
module.exports = defineConfig({
|
module.exports = defineConfig({
|
||||||
devServer: {
|
devServer: {
|
||||||
// Bug 修复:将代理配置为环境变量中定义的 API 基础 URL
|
// Bug 修复:将代理配置为环境变量中定义的 API 基础 URL
|
||||||
proxy: process.env.VUE_APP_API_BASE_URL,
|
proxy: {
|
||||||
client: {
|
'/xiaozhi-esp32-api': {
|
||||||
overlay: false,
|
target: process.env.VUE_APP_API_BASE_URL || 'http://localhost:8002', // 后端 API 的基础 URL
|
||||||
|
changeOrigin: true, // 允许跨域
|
||||||
|
// pathRewrite: {
|
||||||
|
// '^/api': '', // 路径重写
|
||||||
|
// },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
client: {
|
||||||
|
overlay: false,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
});
|
||||||
})
|
|
||||||
|
|||||||
Reference in New Issue
Block a user