创建 mall-spring-boot-starter-security-user 模块,用于用户的认证拦截器
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
package cn.iocoder.mall.user.application.controller.users;
|
||||
|
||||
import cn.iocoder.common.framework.constant.UserTypeEnum;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.system.api.OAuth2Service;
|
||||
import cn.iocoder.mall.system.api.bo.oauth2.OAuth2AccessTokenBO;
|
||||
import cn.iocoder.mall.system.api.dto.oauth2.OAuth2RefreshTokenDTO;
|
||||
import cn.iocoder.mall.user.api.UserService;
|
||||
import io.swagger.annotations.Api;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("users/passport")
|
||||
@Api("Passport 模块")
|
||||
public class PassportController {
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.consumer.OAuth2Service.version}")
|
||||
private OAuth2Service oauth2Service;
|
||||
@Reference(validation = "true", version = "${dubbo.provider.UserService.version}")
|
||||
private UserService userService;
|
||||
|
||||
// TODO 功能:手机密码登陆
|
||||
// @PostMapping("/mobile/pwd/login")
|
||||
// public OAuth2AccessToken mobileLogin(@RequestParam("mobile") String mobile,
|
||||
// @RequestParam("password") String password) {
|
||||
// return oauth2Service.getAccessToken(clientId, clientSecret, mobile, password);
|
||||
// }
|
||||
|
||||
// TODO 芋艿,改绑手机号
|
||||
|
||||
// TODO 功能:qq 登陆
|
||||
@PostMapping("/qq/login")
|
||||
public String qqLogin() {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO 功能:qq 绑定
|
||||
@PostMapping("/qq/bind")
|
||||
public String qqBind() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@PostMapping("/refresh_token") // TODO 功能:刷新 token
|
||||
public CommonResult<OAuth2AccessTokenBO> refreshToken(@RequestParam("refreshToken") String refreshToken) {
|
||||
return success(oauth2Service.refreshToken(new OAuth2RefreshTokenDTO().setRefreshToken(refreshToken)
|
||||
.setUserType(UserTypeEnum.USER.getValue())));
|
||||
}
|
||||
|
||||
// TODO 功能:退出,销毁 token
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package cn.iocoder.mall.user.application.controller.users;
|
||||
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.user.api.UserService;
|
||||
import cn.iocoder.mall.user.api.bo.UserBO;
|
||||
import cn.iocoder.mall.user.api.dto.UserUpdateDTO;
|
||||
import cn.iocoder.mall.user.application.convert.UserConvert;
|
||||
import cn.iocoder.mall.user.application.vo.users.UsersUserVO;
|
||||
import cn.iocoder.mall.user.sdk.annotation.RequiresLogin;
|
||||
import cn.iocoder.mall.user.sdk.context.UserSecurityContextHolder;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.apache.dubbo.config.annotation.Reference;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import static cn.iocoder.common.framework.vo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/users/user")
|
||||
@Api("用户模块")
|
||||
public class UserController {
|
||||
|
||||
@Reference(validation = "true", version = "${dubbo.provider.UserService.version}")
|
||||
private UserService userService;
|
||||
|
||||
@GetMapping("/info")
|
||||
@RequiresLogin
|
||||
@ApiOperation(value = "用户信息")
|
||||
public CommonResult<UsersUserVO> info() {
|
||||
UserBO userResult = userService.getUser(UserSecurityContextHolder.getContext().getUserId());
|
||||
return success(UserConvert.INSTANCE.convert2(userResult));
|
||||
}
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package cn.iocoder.mall.user.application.convert;
|
||||
|
||||
import cn.iocoder.mall.user.api.bo.UserBO;
|
||||
import cn.iocoder.mall.user.api.bo.UserPageBO;
|
||||
import cn.iocoder.mall.user.application.vo.admins.AdminsUserPageVO;
|
||||
import cn.iocoder.mall.user.application.vo.users.UsersUserVO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface UserConvert {
|
||||
|
||||
UserConvert INSTANCE = Mappers.getMapper(UserConvert.class);
|
||||
|
||||
@Mappings({})
|
||||
AdminsUserPageVO convert(UserPageBO result);
|
||||
|
||||
@Mappings({})
|
||||
UsersUserVO convert2(UserBO result);
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package cn.iocoder.mall.user.application.vo.users;
|
||||
|
||||
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 UsersAccessTokenVO {
|
||||
|
||||
@ApiModelProperty(value = "访问令牌", required = true, example = "2e3d7635c15e47e997611707a237859f")
|
||||
private String accessToken;
|
||||
@ApiModelProperty(value = "刷新令牌", required = true, example = "d091e7c35bbb4313b0f557a6ef23d033")
|
||||
private String refreshToken;
|
||||
@ApiModelProperty(value = "过期时间,单位:秒", required = true, example = "2879")
|
||||
private Integer expiresIn;
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package cn.iocoder.mall.user.application.vo.users;
|
||||
|
||||
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 UsersMobileRegisterVO {
|
||||
|
||||
@ApiModelProperty(value = "访问令牌", required = true, example = "2e3d7635c15e47e997611707a237859f")
|
||||
private String accessToken;
|
||||
@ApiModelProperty(value = "刷新令牌", required = true, example = "d091e7c35bbb4313b0f557a6ef23d033")
|
||||
private String refreshToken;
|
||||
@ApiModelProperty(value = "过期时间,单位:秒", required = true, example = "2879")
|
||||
private Integer expiresIn;
|
||||
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
package cn.iocoder.mall.user.application.vo.users;
|
||||
|
||||
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 UsersUserVO {
|
||||
|
||||
@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;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user