|
@@ -9,6 +9,7 @@ import com.genersoft.iot.vmp.service.IDeviceService;
|
|
|
import com.genersoft.iot.vmp.storager.dao.dto.UserAccount;
|
|
|
import com.genersoft.iot.vmp.utils.StpUserUtil;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
|
|
+import com.genersoft.iot.vmp.vmanager.bean.UserLoginResult;
|
|
|
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
import io.swagger.v3.oas.annotations.Parameter;
|
|
@@ -70,8 +71,8 @@ public class AccountController {
|
|
|
@Operation(summary = "登录")
|
|
|
@Parameter(name = "account", description = "登陆账号", required = true)
|
|
|
@Parameter(name = "password", description = "密码", required = true)
|
|
|
- public WVPResult<SaTokenInfo> login(@RequestParam String account,
|
|
|
- @RequestParam String password) {
|
|
|
+ public WVPResult<UserLoginResult> login(@RequestParam String account,
|
|
|
+ @RequestParam String password) {
|
|
|
logger.info("[登录账号] account {}", account);
|
|
|
UserAccount userAccount = accountService.login(account, password);
|
|
|
if (userAccount == null) {
|
|
@@ -80,8 +81,68 @@ public class AccountController {
|
|
|
"账号或者密码错误");
|
|
|
}
|
|
|
StpUserUtil.login(userAccount.getId());
|
|
|
+ logger.info("[登录账号] 用户: {} 登录成功", account);
|
|
|
+ // 登录成功后返回 token 信息, 以及用户名, 头像等信息
|
|
|
+ UserLoginResult userLoginResult = new UserLoginResult(
|
|
|
+ StpUserUtil.getTokenInfo(),
|
|
|
+ userAccount.getName(),
|
|
|
+ userAccount.getId()
|
|
|
+ );
|
|
|
+ return WVPResult.success(userLoginResult);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 注销
|
|
|
+ @GetMapping("/logout")
|
|
|
+ @Operation(summary = "登出账户")
|
|
|
+ public WVPResult<String> logout() {
|
|
|
+ StpUserUtil.logout();
|
|
|
+ return WVPResult.success("ok");
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/rename")
|
|
|
+ @Operation(summary = "重命名")
|
|
|
+ @Parameter(name = "name", description = "新名称", required = true)
|
|
|
+ public WVPResult<UserLoginResult> rename(@RequestParam String name) {
|
|
|
+ logger.info("[重命名] name {}", name);
|
|
|
+ String accountId = StpUserUtil.getLoginId().toString();
|
|
|
+ boolean flag = accountService.updateName(accountId, name);
|
|
|
+ // 登录成功后返回 token 信息, 以及用户名, 头像等信息
|
|
|
+ if (!flag) {
|
|
|
+ return WVPResult.fail(
|
|
|
+ ErrorCode.ERROR100,
|
|
|
+ "重命名失败");
|
|
|
+ }
|
|
|
+ UserLoginResult userLoginResult = new UserLoginResult(
|
|
|
+ StpUserUtil.getTokenInfo(),
|
|
|
+ name,
|
|
|
+ Integer.parseInt(accountId)
|
|
|
+ );
|
|
|
+ return WVPResult.success(userLoginResult);
|
|
|
+ }
|
|
|
|
|
|
- return WVPResult.success(StpUserUtil.getTokenInfo());
|
|
|
+ // 修改密码
|
|
|
+ @GetMapping("/repasswd")
|
|
|
+ @Operation(summary = "修改密码")
|
|
|
+ @Parameter(name = "oldPasswd", description = "旧密码", required = true)
|
|
|
+ @Parameter(name = "newPasswd", description = "新密码", required = true)
|
|
|
+ public WVPResult<String> rePasswd(@Parameter String oldPasswd, @Parameter String newPasswd) {
|
|
|
+ logger.info("[修改密码] oldPasswd {}", oldPasswd);
|
|
|
+ String accountId = StpUserUtil.getLoginId().toString();
|
|
|
+ // 检查密码是否正确
|
|
|
+ UserAccount userAccount = accountService.getByAccountIdAndPassword(accountId, oldPasswd);
|
|
|
+ if (userAccount == null) {
|
|
|
+ return WVPResult.fail(
|
|
|
+ ErrorCode.ERROR404,
|
|
|
+ "请确认密码是否正确");
|
|
|
+ }
|
|
|
+ boolean flag = accountService.updatePassword(accountId, newPasswd);
|
|
|
+ // 登录成功后返回 token 信息, 以及用户名, 头像等信息
|
|
|
+ if (!flag) {
|
|
|
+ return WVPResult.fail(
|
|
|
+ ErrorCode.ERROR100,
|
|
|
+ "修改密码失败");
|
|
|
+ }
|
|
|
+ return WVPResult.success("ok");
|
|
|
}
|
|
|
|
|
|
@GetMapping("/load/bind")
|