创建 mall-spring-boot-starter-security-user 模块,用于用户的认证拦截器
This commit is contained in:
@@ -1,7 +1,55 @@
|
||||
package cn.iocoder.mall.userweb.controller.user;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.security.user.core.context.UserSecurityContextHolder;
|
||||
import cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO;
|
||||
import cn.iocoder.mall.userweb.manager.user.UserManager;
|
||||
import cn.iocoder.security.annotations.RequiresAuthenticate;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@Api(tags = "用户信息 API")
|
||||
@RestController
|
||||
@RequestMapping("/user")
|
||||
public class UserController {
|
||||
|
||||
@Autowired
|
||||
private UserManager userManager;
|
||||
|
||||
@ApiOperation(value = "用户信息")
|
||||
@GetMapping("/info")
|
||||
@RequiresAuthenticate
|
||||
public CommonResult<UserInfoVO> info() {
|
||||
UserInfoVO user = userManager.getUser(UserSecurityContextHolder.getUserId());
|
||||
return success(user);
|
||||
}
|
||||
|
||||
// @PostMapping("/update_avatar")
|
||||
// @RequiresLogin
|
||||
// @ApiOperation(value = "更新头像")
|
||||
// public CommonResult<Boolean> updateAvatar(@RequestParam("avatar") String avatar) {
|
||||
// // 创建
|
||||
// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
|
||||
// .setAvatar(avatar);
|
||||
// // 更新头像
|
||||
// return success(userService.updateUser(userUpdateDTO));
|
||||
// }
|
||||
//
|
||||
// @PostMapping("/update_nickname")
|
||||
// @RequiresLogin
|
||||
// @ApiOperation(value = "更新昵称")
|
||||
// public CommonResult<Boolean> updateNickname(@RequestParam("nickname") String nickname) {
|
||||
// // 创建
|
||||
// UserUpdateDTO userUpdateDTO = new UserUpdateDTO().setId(UserSecurityContextHolder.getContext().getUserId())
|
||||
// .setNickname(nickname);
|
||||
// // 更新头像
|
||||
// return success(userService.updateUser(userUpdateDTO));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package cn.iocoder.mall.userweb.controller.user.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
@ApiModel("用户信息 VO")
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class UserInfoVO {
|
||||
|
||||
@ApiModelProperty(value = "用户编号", required = true, example = "123")
|
||||
private Integer id;
|
||||
@ApiModelProperty(value = "手机号", required = true, example = "15601691300")
|
||||
private String mobile;
|
||||
@ApiModelProperty(value = "昵称", required = true, example = "小王")
|
||||
private String nickname;
|
||||
@ApiModelProperty(value = "头像", required = true, example = "http://www.iocoder.cn/xxx.jpg")
|
||||
private String avatar;
|
||||
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
package cn.iocoder.mall.userweb.convert;
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.mall.userweb.convert.user;
|
||||
|
||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
||||
import cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface UserConvert {
|
||||
|
||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||
|
||||
UserInfoVO convert(UserVO bean);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.iocoder.mall.userweb.manager.user;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.userservice.rpc.user.UserRpc;
|
||||
import cn.iocoder.mall.userservice.rpc.user.vo.UserVO;
|
||||
import cn.iocoder.mall.userweb.controller.user.vo.UserInfoVO;
|
||||
import cn.iocoder.mall.userweb.convert.user.UserConvert;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class UserManager {
|
||||
|
||||
@Reference(version = "${dubbo.consumer.UserRpc.version}", validation = "false")
|
||||
private UserRpc userRpc;
|
||||
|
||||
public UserInfoVO getUser(Integer id) {
|
||||
CommonResult<UserVO> userResult = userRpc.getUser(id);
|
||||
userResult.checkError();
|
||||
return UserConvert.INSTANCE.convert(userResult.getData());
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user