获取用户信息-未测试
This commit is contained in:
parent
5ba73606ca
commit
d2d8b7f17a
|
@ -4,10 +4,9 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="6ee93b58-a7e0-45a0-9e98-4c363b192afb" name="Changes" comment="用户注册">
|
||||
<list default="true" id="6ee93b58-a7e0-45a0-9e98-4c363b192afb" name="Changes" comment="会员登录">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/controller/UserinfoController.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/mapper/UserinfoMapper.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/UserinfoService.java" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java" beforeDir="false" afterPath="$PROJECT_DIR$/spzx-service/service-user/src/main/java/cn/bunny/user/service/impl/UserinfoServiceImpl.java" afterDir="false" />
|
||||
</list>
|
||||
|
@ -188,7 +187,7 @@
|
|||
<updated>1703487755445</updated>
|
||||
<workItem from="1703487757122" duration="903000" />
|
||||
<workItem from="1703488670206" duration="5932000" />
|
||||
<workItem from="1703549556395" duration="25117000" />
|
||||
<workItem from="1703549556395" duration="26260000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="前端接口初始化;显示商品页面">
|
||||
<option name="closed" value="true" />
|
||||
|
@ -270,7 +269,15 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1703578711882</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="11" />
|
||||
<task id="LOCAL-00011" summary="会员登录">
|
||||
<option name="closed" value="true" />
|
||||
<created>1703580114862</created>
|
||||
<option name="number" value="00011" />
|
||||
<option name="presentableId" value="LOCAL-00011" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1703580114862</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="12" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
|
@ -286,7 +293,8 @@
|
|||
<MESSAGE value="商品详情" />
|
||||
<MESSAGE value="发送验证码" />
|
||||
<MESSAGE value="用户注册" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="用户注册" />
|
||||
<MESSAGE value="会员登录" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="会员登录" />
|
||||
</component>
|
||||
<component name="XDebuggerManager">
|
||||
<pin-to-top-manager>
|
||||
|
|
|
@ -4,14 +4,13 @@ import cn.bunny.common.spzx.model.dto.h5.UserLoginDto;
|
|||
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
||||
import cn.bunny.common.spzx.model.vo.common.Result;
|
||||
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||
import cn.bunny.common.spzx.model.vo.h5.UserInfoVo;
|
||||
import cn.bunny.user.service.UserinfoService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
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 jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@Tag(name = "会员用户接口")
|
||||
@RestController
|
||||
|
@ -20,6 +19,14 @@ public class UserinfoController {
|
|||
@Resource
|
||||
private UserinfoService userinfoService;
|
||||
|
||||
@Operation(summary = "获取当前登录用户信息")
|
||||
@GetMapping("auth/getCurrentUserInfo")
|
||||
public Result getCurrentUserInfo(HttpServletRequest request) {
|
||||
String token = request.getHeader("token");
|
||||
UserInfoVo userInfoVo = UserinfoService.getCurrentUserInfo(token);
|
||||
return Result.build(userInfoVo, ResultCodeEnum.SUCCESS);
|
||||
}
|
||||
|
||||
@Operation(summary = "会员登录")
|
||||
@PostMapping("login")
|
||||
public Result login(@RequestBody UserLoginDto userLoginDto) {
|
||||
|
|
|
@ -2,8 +2,11 @@ package cn.bunny.user.service;
|
|||
|
||||
import cn.bunny.common.spzx.model.dto.h5.UserLoginDto;
|
||||
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
||||
import cn.bunny.common.spzx.model.vo.h5.UserInfoVo;
|
||||
|
||||
public interface UserinfoService {
|
||||
UserInfoVo getCurrentUserInfo(String token);
|
||||
|
||||
// 会员注册
|
||||
void register(UserRegisterDto userLoginDto);
|
||||
|
||||
|
|
|
@ -5,10 +5,13 @@ import cn.bunny.common.spzx.model.dto.h5.UserLoginDto;
|
|||
import cn.bunny.common.spzx.model.dto.h5.UserRegisterDto;
|
||||
import cn.bunny.common.spzx.model.entity.user.UserInfo;
|
||||
import cn.bunny.common.spzx.model.vo.common.ResultCodeEnum;
|
||||
import cn.bunny.common.spzx.model.vo.h5.UserInfoVo;
|
||||
import cn.bunny.user.mapper.UserinfoMapper;
|
||||
import cn.bunny.user.service.UserinfoService;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.nacos.common.utils.StringUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.DigestUtils;
|
||||
|
@ -23,6 +26,23 @@ public class UserinfoServiceImpl implements UserinfoService {
|
|||
@Resource
|
||||
private UserinfoMapper userinfoMapper;
|
||||
|
||||
// 获取当前登录用户信息
|
||||
@Override
|
||||
public UserInfoVo getCurrentUserInfo(String token) {
|
||||
// 从Redis根据token获取用户信息
|
||||
String userJson = (String) redisTemplate.opsForValue().get("user:spzx" + token);
|
||||
if (StringUtils.hasText(userJson)) {
|
||||
throw new BunnyException(ResultCodeEnum.LOGIN_ERROR);
|
||||
}
|
||||
|
||||
UserInfo userinfo = JSON.parseObject(userJson, UserInfo.class);
|
||||
UserInfoVo userInfoVo = new UserInfoVo();
|
||||
assert userinfo != null;
|
||||
BeanUtils.copyProperties(userinfo, userInfoVo);
|
||||
|
||||
return userInfoVo;
|
||||
}
|
||||
|
||||
// 会员注册
|
||||
@Override
|
||||
public void register(UserRegisterDto userRegisterDto) {
|
||||
|
|
Loading…
Reference in New Issue