From 52a6d76d9a6c1c43f824b2aa4d2572478c49f7a0 Mon Sep 17 00:00:00 2001
From: luxiaotao1123 <t1341870251@163.com>
Date: 星期二, 13 二月 2024 21:19:37 +0800
Subject: [PATCH] #
---
zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/sys/controller/AuthController.java | 68 +++++++++++++++++++++++++++++++---
1 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/sys/controller/AuthController.java b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/sys/controller/AuthController.java
index cac933e..bfb8500 100644
--- a/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/sys/controller/AuthController.java
+++ b/zy-asrs-wcs/src/main/java/com/zy/asrs/wcs/sys/controller/AuthController.java
@@ -1,23 +1,27 @@
package com.zy.asrs.wcs.sys.controller;
-import com.zy.asrs.common.web.BaseController;
+import com.zy.asrs.framework.common.Cools;
import com.zy.asrs.framework.common.R;
+import com.zy.asrs.wcs.common.annotation.OperationLog;
import com.zy.asrs.wcs.common.config.ConfigProperties;
import com.zy.asrs.wcs.common.security.JwtSubject;
import com.zy.asrs.wcs.sys.controller.param.LoginParam;
+import com.zy.asrs.wcs.sys.controller.param.UpdatePasswordParam;
import com.zy.asrs.wcs.sys.controller.result.LoginResult;
+import com.zy.asrs.wcs.sys.entity.Menu;
import com.zy.asrs.wcs.sys.entity.User;
import com.zy.asrs.wcs.sys.entity.UserLogin;
+import com.zy.asrs.wcs.sys.service.RoleMenuService;
import com.zy.asrs.wcs.sys.service.UserLoginService;
import com.zy.asrs.wcs.sys.service.UserService;
import com.zy.asrs.wcs.utils.JwtUtil;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-import org.springframework.web.bind.annotation.RestController;
+import com.zy.asrs.wcs.utils.Utils;
+import org.springframework.security.access.prepost.PreAuthorize;
+import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
+import java.util.List;
/**
* 璁よ瘉鎺у埗鍣�
@@ -34,6 +38,8 @@
private UserService userService;
@Resource
private UserLoginService userLoginService;
+ @Resource
+ private RoleMenuService roleMenuService;
@PostMapping("/login")
public R login(@RequestBody LoginParam param, HttpServletRequest request) {
@@ -50,10 +56,60 @@
return R.error("瀵嗙爜閿欒");
}
userLoginService.saveAsync(user.getId(), UserLogin.TYPE_LOGIN, null, hostId, request);
- String accessToken = JwtUtil.buildToken(new JwtSubject(username, hostId),
+ String accessToken = JwtUtil.buildToken(new JwtSubject(username, user.getHostId()),
configProperties.getTokenExpireTime(), configProperties.getTokenKey());
return R.ok("鐧诲綍鎴愬姛").add(new LoginResult(accessToken, user));
}
+ @GetMapping("/auth/user")
+ public R userInfo() {
+ return R.ok(userService.getByIdRel(getLoginUserId()));
+ }
+
+ @GetMapping("/auth/menu")
+ public R userMenu() {
+ List<Menu> menus = roleMenuService.listMenuByUserId(getLoginUserId(), Menu.TYPE_MENU);
+ return R.ok().add(Utils.toTreeData(menus, 0L, Menu::getParentId, Menu::getId, Menu::setChildren));
+ }
+
+ @PreAuthorize("hasAuthority('sys:auth:user')")
+ @OperationLog
+ @PutMapping("/auth/user")
+ public R updateInfo(@RequestBody User user) {
+ user.setId(getLoginUserId());
+ // 涓嶈兘淇敼鐨勫瓧娈�
+ user.setUsername(null);
+ user.setPassword(null);
+ user.setEmailVerified(null);
+ user.setHostId(null);
+ user.setStatus(null);
+ if (userService.updateById(user)) {
+ return R.ok().add(userService.getByIdRel(user.getId()));
+ }
+ return R.error("淇濆瓨澶辫触");
+ }
+
+ @PreAuthorize("hasAuthority('sys:auth:password')")
+ @OperationLog
+ @PutMapping("/auth/password")
+ public R updatePassword(@RequestBody UpdatePasswordParam param) {
+ if (Cools.isEmpty(param.getOldPassword(), param.getPassword())) {
+ return R.error("鍙傛暟涓嶈兘涓虹┖");
+ }
+ Long userId = getLoginUserId();
+ if (userId == null) {
+ return R.error("鏈櫥褰�");
+ }
+ if (!userService.comparePassword(userService.getById(userId).getPassword(), param.getOldPassword())) {
+ return R.error("鍘熷瘑鐮佽緭鍏ヤ笉姝g‘");
+ }
+ User user = new User();
+ user.setId(userId);
+ user.setPassword(userService.encodePassword(param.getPassword()));
+ if (userService.updateById(user)) {
+ return R.ok("淇敼鎴愬姛");
+ }
+ return R.error("淇敼澶辫触");
+ }
}
--
Gitblit v1.9.1