✨Feat: 增加用户登录功能

This commit is contained in:
2025-10-18 17:22:39 +08:00
parent 6a4e0e6f55
commit d9a7f399fb
2 changed files with 38 additions and 0 deletions
@@ -0,0 +1,6 @@
package cn.hezhaohui.thumb.constent;
public class UserConstant {
public static final String LOGIN_USER = "login_user";
}
@@ -0,0 +1,32 @@
package cn.hezhaohui.thumb.controller;
import cn.hezhaohui.thumb.common.BaseResponse;
import cn.hezhaohui.thumb.common.ResultUtils;
import cn.hezhaohui.thumb.constent.UserConstant;
import cn.hezhaohui.thumb.model.entity.User;
import cn.hezhaohui.thumb.service.UserService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("user")
public class UserController {
@Resource
private UserService userService;
@GetMapping("/login")
public BaseResponse<User> login(long userId, HttpServletRequest request) {
User user = userService.getById(userId);
request.getSession().setAttribute(UserConstant.LOGIN_USER, user);
return ResultUtils.sucess(user);
}
@GetMapping("/get/login")
public BaseResponse<User> getLoginUser(HttpServletRequest request) {
User loginUser = (User) request.getSession().getAttribute(UserConstant.LOGIN_USER);
return ResultUtils.sucess(loginUser);
}
}