diff --git a/src/main/java/edu/zrh/healthsystem/controller/LoginController.java b/src/main/java/edu/zrh/healthsystem/controller/LoginController.java index f139cc1..8998f16 100644 --- a/src/main/java/edu/zrh/healthsystem/controller/LoginController.java +++ b/src/main/java/edu/zrh/healthsystem/controller/LoginController.java @@ -1,14 +1,11 @@ package edu.zrh.healthsystem.controller; -import edu.zrh.healthsystem.model.LoginResult; +import edu.zrh.healthsystem.model.LoginResponse; import edu.zrh.healthsystem.model.UserLogin; import edu.zrh.healthsystem.service.LoginService; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; import io.swagger.v3.oas.annotations.tags.Tag; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpSession; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -30,7 +27,7 @@ public class LoginController { */ @PostMapping(value = "/login") @ResponseBody - public LoginResult login(@RequestBody UserLogin userLogin) { + public LoginResponse login(@RequestBody UserLogin userLogin) { return userService.login(userLogin); } @@ -76,7 +73,7 @@ public class LoginController { */ @PostMapping(value = "/register") @ResponseBody - public LoginResult register(@RequestBody UserLogin userLogin) { + public LoginResponse register(@RequestBody UserLogin userLogin) { return userService.register(userLogin); } diff --git a/src/main/java/edu/zrh/healthsystem/entity/UserMainInfo.java b/src/main/java/edu/zrh/healthsystem/entity/UserMainInfo.java index 5e8bf4b..1e9f46e 100644 --- a/src/main/java/edu/zrh/healthsystem/entity/UserMainInfo.java +++ b/src/main/java/edu/zrh/healthsystem/entity/UserMainInfo.java @@ -39,7 +39,10 @@ public class UserMainInfo { @Column(name = "user_email") private String email; - - + /** + * 权限 + */ + @Column(name = "user_permission") + private String permission; } diff --git a/src/main/java/edu/zrh/healthsystem/model/LoginResult.java b/src/main/java/edu/zrh/healthsystem/model/LoginResponse.java similarity index 74% rename from src/main/java/edu/zrh/healthsystem/model/LoginResult.java rename to src/main/java/edu/zrh/healthsystem/model/LoginResponse.java index 244b58f..aae7ba8 100644 --- a/src/main/java/edu/zrh/healthsystem/model/LoginResult.java +++ b/src/main/java/edu/zrh/healthsystem/model/LoginResponse.java @@ -8,12 +8,13 @@ import lombok.Data; */ @Data @AllArgsConstructor -public class LoginResult { +public class LoginResponse { private String data; private Integer code; private String message; private String username; - public LoginResult() { + private String permission; + public LoginResponse() { } } diff --git a/src/main/java/edu/zrh/healthsystem/service/LoginService.java b/src/main/java/edu/zrh/healthsystem/service/LoginService.java index b529de7..398eb00 100644 --- a/src/main/java/edu/zrh/healthsystem/service/LoginService.java +++ b/src/main/java/edu/zrh/healthsystem/service/LoginService.java @@ -2,15 +2,17 @@ package edu.zrh.healthsystem.service; import edu.zrh.healthsystem.entity.UserLoginInfo; import edu.zrh.healthsystem.entity.UserMainInfo; -import edu.zrh.healthsystem.model.LoginResult; +import edu.zrh.healthsystem.model.LoginResponse; import edu.zrh.healthsystem.model.UserLogin; import edu.zrh.healthsystem.repository.LoginRepository; import edu.zrh.healthsystem.repository.UserMainInfoRepository; -import jakarta.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.SignatureAlgorithm; +/** + * @author han + */ @Service public class LoginService { @@ -27,8 +29,8 @@ public class LoginService { * @param userLogin 用户登录信息 * @return LoginResult 登录结果 */ - public LoginResult login(UserLogin userLogin) { - LoginResult result = new LoginResult(); + public LoginResponse login(UserLogin userLogin) { + LoginResponse result = new LoginResponse(); UserLoginInfo storedUser = loginRepository.findByUsername(userLogin.getUsername()); String userId = String.valueOf(storedUser.getId()); UserMainInfo userMainInfo = userMainInfoRepository.findById(Integer.parseInt(userId)).orElse(null); @@ -39,6 +41,7 @@ public class LoginService { // 假设 ID 是 UserLogin 的字段 if (userMainInfo != null) { result.setUsername(userMainInfo.getUsername()); + result.setPermission(userMainInfo.getPermission()); } result.setCode(200); result.setMessage("登录成功"); @@ -57,8 +60,8 @@ public class LoginService { * @param userLogin 用户注册信息 * @return LoginResult 注册结果 */ - public LoginResult register(UserLogin userLogin) { - LoginResult result = new LoginResult(); + public LoginResponse register(UserLogin userLogin) { + LoginResponse result = new LoginResponse(); // 假设我们先验证用户是否已经存在 UserLoginInfo existingUser = loginRepository.findByUsername(userLogin.getUsername());