parent
eb1ea9b5fe
commit
495669ac84
@ -0,0 +1,12 @@
|
||||
package dto;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class UserLoginDto {
|
||||
private String userId;
|
||||
private String nickName;
|
||||
private String roles;
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
package com.luoo.user.util;
|
||||
package util;
|
||||
|
||||
public class StringTools {
|
||||
|
||||
|
||||
public static boolean isEmpty(String str) {
|
||||
if (null == str || "".equals(str) || "null".equals(str) || "\u0000".equals(str)) {
|
||||
return true;
|
@ -0,0 +1,50 @@
|
||||
package com.luoo.user.controller;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestHeader;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.luoo.user.annotation.GlobalInterceptor;
|
||||
import com.luoo.user.annotation.VerifyParam;
|
||||
import com.luoo.user.constants.Constants;
|
||||
import com.luoo.user.dto.response.UserRespDTO;
|
||||
import com.luoo.user.pojo.User;
|
||||
import com.luoo.user.service.UserService;
|
||||
|
||||
import api.Result;
|
||||
import api.StatusCode;
|
||||
import dto.UserLoginDto;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import util.JwtUtil;
|
||||
|
||||
@RestController
|
||||
@CrossOrigin
|
||||
@RequestMapping("/my")
|
||||
@Api(tags = "MyController")
|
||||
public class MyController {
|
||||
@Autowired
|
||||
private JwtUtil jwtUtil;
|
||||
@Autowired
|
||||
private UserService userService;
|
||||
|
||||
@ApiOperation(value = "1.获取个人信息")
|
||||
@PostMapping("/getUserInfo/{token}")
|
||||
@GlobalInterceptor
|
||||
public Result getUserInfo(@RequestHeader(value = "token", required = false) String token) {
|
||||
UserLoginDto userLoginDto = jwtUtil.getUserLoginDto(token);
|
||||
if (null == userLoginDto) {
|
||||
return Result.validateFailed();
|
||||
}
|
||||
User user = userService.findById(userLoginDto.getUserId());
|
||||
UserRespDTO userRespDTO = new UserRespDTO();
|
||||
BeanUtils.copyProperties(user, userRespDTO);
|
||||
userRespDTO.setToken(token);
|
||||
return Result.success(userRespDTO);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue