增加头部名称

This commit is contained in:
zrh050423 2024-12-21 16:27:21 +08:00
parent 9ee7acadd0
commit df2346bfa6
4 changed files with 20 additions and 16 deletions

View File

@ -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);
}

View File

@ -39,7 +39,10 @@ public class UserMainInfo {
@Column(name = "user_email")
private String email;
/**
* 权限
*/
@Column(name = "user_permission")
private String permission;
}

View File

@ -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() {
}
}

View File

@ -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());