Commit c402077961560bac0fbf9ac51b75bc86e2a384b4
1 parent
7227664f
进一步重构社交登陆的实现
Showing
18 changed files
with
116 additions
and
123 deletions
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/AppAuthController.java
| ... | ... | @@ -23,7 +23,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 23 | 23 | |
| 24 | 24 | @Api(tags = "用户 APP - 认证") |
| 25 | 25 | @RestController |
| 26 | -@RequestMapping("/member/") | |
| 26 | +@RequestMapping("/member/auth") | |
| 27 | 27 | @Validated |
| 28 | 28 | @Slf4j |
| 29 | 29 | public class AppAuthController { |
| ... | ... | @@ -33,7 +33,6 @@ public class AppAuthController { |
| 33 | 33 | |
| 34 | 34 | @PostMapping("/login") |
| 35 | 35 | @ApiOperation("使用手机 + 密码登录") |
| 36 | - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 | |
| 37 | 36 | public CommonResult<AppAuthLoginRespVO> login(@RequestBody @Valid AppAuthLoginReqVO reqVO) { |
| 38 | 37 | String token = authService.login(reqVO, getClientIP(), getUserAgent()); |
| 39 | 38 | // 返回结果 |
| ... | ... | @@ -42,7 +41,6 @@ public class AppAuthController { |
| 42 | 41 | |
| 43 | 42 | @PostMapping("/sms-login") |
| 44 | 43 | @ApiOperation("使用手机 + 验证码登录") |
| 45 | - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 | |
| 46 | 44 | public CommonResult<AppAuthLoginRespVO> smsLogin(@RequestBody @Valid AppAuthSmsLoginReqVO reqVO) { |
| 47 | 45 | String token = authService.smsLogin(reqVO, getClientIP(), getUserAgent()); |
| 48 | 46 | // 返回结果 |
| ... | ... | @@ -51,7 +49,6 @@ public class AppAuthController { |
| 51 | 49 | |
| 52 | 50 | @PostMapping("/send-sms-code") |
| 53 | 51 | @ApiOperation(value = "发送手机验证码") |
| 54 | - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 | |
| 55 | 52 | public CommonResult<Boolean> sendSmsCode(@RequestBody @Valid AppAuthSendSmsReqVO reqVO) { |
| 56 | 53 | authService.sendSmsCode(getLoginUserId(), reqVO); |
| 57 | 54 | return success(true); |
| ... | ... | @@ -60,7 +57,6 @@ public class AppAuthController { |
| 60 | 57 | @PostMapping("/reset-password") |
| 61 | 58 | @ApiOperation(value = "重置密码", notes = "用户忘记密码时使用") |
| 62 | 59 | @PreAuthenticated |
| 63 | - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 | |
| 64 | 60 | public CommonResult<Boolean> resetPassword(@RequestBody @Valid AppAuthResetPasswordReqVO reqVO) { |
| 65 | 61 | authService.resetPassword(reqVO); |
| 66 | 62 | return success(true); |
| ... | ... | @@ -87,35 +83,18 @@ public class AppAuthController { |
| 87 | 83 | return CommonResult.success(authService.getSocialAuthorizeUrl(type, redirectUri)); |
| 88 | 84 | } |
| 89 | 85 | |
| 90 | - @PostMapping("/social-login") | |
| 91 | - @ApiOperation(value = "社交登录,使用 code 授权码", notes = "适合未登录的用户,但是社交账号已绑定用户") | |
| 92 | - public CommonResult<AppAuthLoginRespVO> socialLogin(@RequestBody @Valid AppAuthSocialLoginReqVO reqVO) { | |
| 93 | - String token = authService.socialLogin(reqVO, getClientIP(), getUserAgent()); | |
| 86 | + @PostMapping("/social-quick-login") | |
| 87 | + @ApiOperation(value = "社交快捷登录,使用 code 授权码", notes = "适合未登录的用户,但是社交账号已绑定用户") | |
| 88 | + public CommonResult<AppAuthLoginRespVO> socialLogin(@RequestBody @Valid AppAuthSocialQuickLoginReqVO reqVO) { | |
| 89 | + String token = authService.socialQuickLogin(reqVO, getClientIP(), getUserAgent()); | |
| 94 | 90 | return success(AppAuthLoginRespVO.builder().token(token).build()); |
| 95 | 91 | } |
| 96 | 92 | |
| 97 | - @PostMapping("/social-login2") | |
| 98 | - @ApiOperation(value = "社交登录,使用 手机号 + 手机验证码", notes = "适合未登录的用户,进行登录 + 绑定") | |
| 99 | - @OperateLog(enable = false) // 避免 Post 请求被记录操作日志 | |
| 100 | - public CommonResult<AppAuthLoginRespVO> socialLogin2(@RequestBody @Valid AppAuthSocialLogin2ReqVO reqVO) { | |
| 101 | - String token = authService.socialLogin2(reqVO, getClientIP(), getUserAgent()); | |
| 93 | + @PostMapping("/social-bind-login") | |
| 94 | + @ApiOperation(value = "社交绑定登录,使用 手机号 + 手机验证码", notes = "适合未登录的用户,进行登录 + 绑定") | |
| 95 | + public CommonResult<AppAuthLoginRespVO> socialLogin2(@RequestBody @Valid AppAuthSocialBindLoginReqVO reqVO) { | |
| 96 | + String token = authService.socialBindLogin(reqVO, getClientIP(), getUserAgent()); | |
| 102 | 97 | return success(AppAuthLoginRespVO.builder().token(token).build()); |
| 103 | 98 | } |
| 104 | 99 | |
| 105 | - @PostMapping("/social-bind") | |
| 106 | - @ApiOperation(value = "社交绑定,使用 code 授权码", notes = "使用在用户已经登录的情况下") | |
| 107 | - @PreAuthenticated | |
| 108 | - public CommonResult<Boolean> socialBind(@RequestBody @Valid AppAuthSocialBindReqVO reqVO) { | |
| 109 | - authService.socialBind(getLoginUserId(), reqVO); | |
| 110 | - return CommonResult.success(true); | |
| 111 | - } | |
| 112 | - | |
| 113 | - @DeleteMapping("/social-unbind") | |
| 114 | - @ApiOperation("取消社交绑定") | |
| 115 | - @PreAuthenticated | |
| 116 | - public CommonResult<Boolean> socialUnbind(@RequestBody AppAuthSocialUnbindReqVO reqVO) { | |
| 117 | - authService.unbindSocialUser(getLoginUserId(), reqVO); | |
| 118 | - return CommonResult.success(true); | |
| 119 | - } | |
| 120 | - | |
| 121 | 100 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthSocialLogin2ReqVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthSocialBindLoginReqVO.java
| ... | ... | @@ -14,12 +14,12 @@ import javax.validation.constraints.NotEmpty; |
| 14 | 14 | import javax.validation.constraints.NotNull; |
| 15 | 15 | import javax.validation.constraints.Pattern; |
| 16 | 16 | |
| 17 | -@ApiModel("用户 APP - 社交登录 Request VO,使用 code 授权码 + 账号密码") | |
| 17 | +@ApiModel("用户 APP - 社交绑定登录 Request VO,使用 code 授权码 + 账号密码") | |
| 18 | 18 | @Data |
| 19 | 19 | @NoArgsConstructor |
| 20 | 20 | @AllArgsConstructor |
| 21 | 21 | @Builder |
| 22 | -public class AppAuthSocialLogin2ReqVO { | |
| 22 | +public class AppAuthSocialBindLoginReqVO { | |
| 23 | 23 | |
| 24 | 24 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") |
| 25 | 25 | @InEnum(SocialTypeEnum.class) |
| ... | ... | @@ -45,5 +45,4 @@ public class AppAuthSocialLogin2ReqVO { |
| 45 | 45 | @Pattern(regexp = "^[0-9]+$", message = "手机验证码必须都是数字") |
| 46 | 46 | private String smsCode; |
| 47 | 47 | |
| 48 | - | |
| 49 | 48 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthSocialBindReqVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthSocialQuickLoginReqVO.java
| ... | ... | @@ -12,12 +12,12 @@ import lombok.NoArgsConstructor; |
| 12 | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | import javax.validation.constraints.NotNull; |
| 14 | 14 | |
| 15 | -@ApiModel("用户 APP - 社交绑定 Request VO,使用 code 授权码") | |
| 15 | +@ApiModel("用户 APP - 社交快捷登录 Request VO,使用 code 授权码") | |
| 16 | 16 | @Data |
| 17 | 17 | @NoArgsConstructor |
| 18 | 18 | @AllArgsConstructor |
| 19 | 19 | @Builder |
| 20 | -public class AppAuthSocialBindReqVO { | |
| 20 | +public class AppAuthSocialQuickLoginReqVO { | |
| 21 | 21 | |
| 22 | 22 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") |
| 23 | 23 | @InEnum(SocialTypeEnum.class) | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/AppSocialUserController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.controller.app.social; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; | |
| 6 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | |
| 7 | +import cn.iocoder.yudao.module.member.convert.social.SocialUserConvert; | |
| 8 | +import cn.iocoder.yudao.module.system.api.social.SocialUserApi; | |
| 9 | +import io.swagger.annotations.Api; | |
| 10 | +import io.swagger.annotations.ApiOperation; | |
| 11 | +import org.springframework.validation.annotation.Validated; | |
| 12 | +import org.springframework.web.bind.annotation.*; | |
| 13 | + | |
| 14 | +import javax.annotation.Resource; | |
| 15 | +import javax.validation.Valid; | |
| 16 | + | |
| 17 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 18 | + | |
| 19 | +@Api(tags = "用户 App - 社交用户") | |
| 20 | +@RestController | |
| 21 | +@RequestMapping("/system/social-user") | |
| 22 | +@Validated | |
| 23 | +public class AppSocialUserController { | |
| 24 | + | |
| 25 | + @Resource | |
| 26 | + private SocialUserApi socialUserApi; | |
| 27 | + | |
| 28 | + @PostMapping("/bind") | |
| 29 | + @ApiOperation("社交绑定,使用 code 授权码") | |
| 30 | + public CommonResult<Boolean> socialBind(@RequestBody @Valid AppSocialUserBindReqVO reqVO) { | |
| 31 | + socialUserApi.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), reqVO)); | |
| 32 | + return CommonResult.success(true); | |
| 33 | + } | |
| 34 | + | |
| 35 | + @DeleteMapping("/unbind") | |
| 36 | + @ApiOperation("取消社交绑定") | |
| 37 | + public CommonResult<Boolean> socialUnbind(@RequestBody AppSocialUserUnbindReqVO reqVO) { | |
| 38 | + socialUserApi.unbindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.MEMBER.getValue(), reqVO)); | |
| 39 | + return CommonResult.success(true); | |
| 40 | + } | |
| 41 | + | |
| 42 | +} | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthSocialLoginReqVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserBindReqVO.java
| 1 | -package cn.iocoder.yudao.module.member.controller.app.auth.vo; | |
| 1 | +package cn.iocoder.yudao.module.member.controller.app.social.vo; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | 4 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| ... | ... | @@ -12,12 +12,12 @@ import lombok.NoArgsConstructor; |
| 12 | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | import javax.validation.constraints.NotNull; |
| 14 | 14 | |
| 15 | -@ApiModel("用户 APP - 社交登录 Request VO,使用 code 授权码") | |
| 15 | +@ApiModel("用户 APP - 社交绑定 Request VO,使用 code 授权码") | |
| 16 | 16 | @Data |
| 17 | 17 | @NoArgsConstructor |
| 18 | 18 | @AllArgsConstructor |
| 19 | 19 | @Builder |
| 20 | -public class AppAuthSocialLoginReqVO { | |
| 20 | +public class AppSocialUserBindReqVO { | |
| 21 | 21 | |
| 22 | 22 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") |
| 23 | 23 | @InEnum(SocialTypeEnum.class) | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/auth/vo/AppAuthSocialUnbindReqVO.java renamed to yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/controller/app/social/vo/AppSocialUserUnbindReqVO.java
| 1 | -package cn.iocoder.yudao.module.member.controller.app.auth.vo; | |
| 1 | +package cn.iocoder.yudao.module.member.controller.app.social.vo; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | 4 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| ... | ... | @@ -12,20 +12,20 @@ import lombok.NoArgsConstructor; |
| 12 | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | import javax.validation.constraints.NotNull; |
| 14 | 14 | |
| 15 | -@ApiModel("用户 APP - 取消社交绑定 Request VO,使用 code 授权码") | |
| 15 | +@ApiModel("用户 APP - 取消社交绑定 Request VO") | |
| 16 | 16 | @Data |
| 17 | 17 | @NoArgsConstructor |
| 18 | 18 | @AllArgsConstructor |
| 19 | 19 | @Builder |
| 20 | -public class AppAuthSocialUnbindReqVO { | |
| 20 | +public class AppSocialUserUnbindReqVO { | |
| 21 | 21 | |
| 22 | 22 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 SysUserSocialTypeEnum 枚举值") |
| 23 | 23 | @InEnum(SocialTypeEnum.class) |
| 24 | 24 | @NotNull(message = "社交平台的类型不能为空") |
| 25 | 25 | private Integer type; |
| 26 | 26 | |
| 27 | - @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 28 | - @NotEmpty(message = "社交的全局编号不能为空") | |
| 29 | - private String unionId; | |
| 27 | + @ApiModelProperty(value = "社交用户的 openid", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 28 | + @NotEmpty(message = "社交用户的 openid 不能为空") | |
| 29 | + private String openid; | |
| 30 | 30 | |
| 31 | 31 | } | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/auth/AuthConvert.java
| ... | ... | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.member.convert.auth; |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 5 | 5 | import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; |
| 6 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | |
| 6 | 7 | import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; |
| 7 | 8 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeSendReqDTO; |
| 8 | 9 | import cn.iocoder.yudao.module.system.api.sms.dto.code.SmsCodeUseReqDTO; |
| ... | ... | @@ -26,10 +27,9 @@ public interface AuthConvert { |
| 26 | 27 | return convert0(bean).setUserType(UserTypeEnum.MEMBER.getValue()); |
| 27 | 28 | } |
| 28 | 29 | |
| 29 | - SocialUserBindReqDTO convert(Long userId, Integer userType, AppAuthSocialBindReqVO reqVO); | |
| 30 | - SocialUserBindReqDTO convert(Long userId, Integer userType, AppAuthSocialLogin2ReqVO reqVO); | |
| 31 | - SocialUserBindReqDTO convert(Long userId, Integer userType, AppAuthSocialLoginReqVO reqVO); | |
| 32 | - SocialUserUnbindReqDTO convert(Long userId, Integer userType, AppAuthSocialUnbindReqVO reqVO); | |
| 30 | + SocialUserBindReqDTO convert(Long userId, Integer userType, AppAuthSocialBindLoginReqVO reqVO); | |
| 31 | + SocialUserBindReqDTO convert(Long userId, Integer userType, AppAuthSocialQuickLoginReqVO reqVO); | |
| 32 | + SocialUserUnbindReqDTO convert(Long userId, Integer userType, AppSocialUserUnbindReqVO reqVO); | |
| 33 | 33 | |
| 34 | 34 | SmsCodeSendReqDTO convert(AppAuthSendSmsReqVO reqVO); |
| 35 | 35 | SmsCodeUseReqDTO convert(AppAuthResetPasswordReqVO reqVO, SmsSceneEnum scene, String usedIp); | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/convert/social/SocialUserConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.member.convert.social; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; | |
| 4 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; | |
| 6 | +import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; | |
| 7 | +import org.mapstruct.Mapper; | |
| 8 | +import org.mapstruct.factory.Mappers; | |
| 9 | + | |
| 10 | +@Mapper | |
| 11 | +public interface SocialUserConvert { | |
| 12 | + | |
| 13 | + SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class); | |
| 14 | + | |
| 15 | + SocialUserBindReqDTO convert(Long userId, Integer userType, AppSocialUserBindReqVO reqVO); | |
| 16 | + | |
| 17 | + SocialUserUnbindReqDTO convert(Long userId, Integer userType, AppSocialUserUnbindReqVO reqVO); | |
| 18 | + | |
| 19 | +} | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthService.java
| ... | ... | @@ -2,6 +2,8 @@ package cn.iocoder.yudao.module.member.service.auth; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.security.core.service.SecurityAuthFrameworkService; |
| 4 | 4 | import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; |
| 5 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; | |
| 6 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | |
| 5 | 7 | |
| 6 | 8 | import javax.validation.Valid; |
| 7 | 9 | |
| ... | ... | @@ -43,7 +45,7 @@ public interface MemberAuthService extends SecurityAuthFrameworkService { |
| 43 | 45 | * @param userAgent 用户 UA |
| 44 | 46 | * @return 身份令牌,使用 JWT 方式 |
| 45 | 47 | */ |
| 46 | - String socialLogin(@Valid AppAuthSocialLoginReqVO reqVO, String userIp, String userAgent); | |
| 48 | + String socialQuickLogin(@Valid AppAuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent); | |
| 47 | 49 | |
| 48 | 50 | /** |
| 49 | 51 | * 社交登录,使用 手机号 + 手机验证码 |
| ... | ... | @@ -53,23 +55,7 @@ public interface MemberAuthService extends SecurityAuthFrameworkService { |
| 53 | 55 | * @param userAgent 用户 UA |
| 54 | 56 | * @return 身份令牌,使用 JWT 方式 |
| 55 | 57 | */ |
| 56 | - String socialLogin2(@Valid AppAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent); | |
| 57 | - | |
| 58 | - /** | |
| 59 | - * 社交绑定,使用 code 授权码 | |
| 60 | - * | |
| 61 | - * @param userId 用户编号 | |
| 62 | - * @param reqVO 绑定信息 | |
| 63 | - */ | |
| 64 | - void socialBind(Long userId, @Valid AppAuthSocialBindReqVO reqVO); | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * 取消社交绑定 | |
| 68 | - * | |
| 69 | - * @param userId 用户编号 | |
| 70 | - * @param reqVO 解绑信息 | |
| 71 | - */ | |
| 72 | - void unbindSocialUser(Long userId, @Valid AppAuthSocialUnbindReqVO reqVO); | |
| 58 | + String socialBindLogin(@Valid AppAuthSocialBindLoginReqVO reqVO, String userIp, String userAgent); | |
| 73 | 59 | |
| 74 | 60 | /** |
| 75 | 61 | * 获得社交认证 URL | ... | ... |
yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/service/auth/MemberAuthServiceImpl.java
| ... | ... | @@ -8,6 +8,8 @@ import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 8 | 8 | import cn.iocoder.yudao.framework.security.core.LoginUser; |
| 9 | 9 | import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePasswordAuthenticationToken; |
| 10 | 10 | import cn.iocoder.yudao.module.member.controller.app.auth.vo.*; |
| 11 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserBindReqVO; | |
| 12 | +import cn.iocoder.yudao.module.member.controller.app.social.vo.AppSocialUserUnbindReqVO; | |
| 11 | 13 | import cn.iocoder.yudao.module.member.convert.auth.AuthConvert; |
| 12 | 14 | import cn.iocoder.yudao.module.member.dal.dataobject.user.MemberUserDO; |
| 13 | 15 | import cn.iocoder.yudao.module.member.dal.mysql.user.MemberUserMapper; |
| ... | ... | @@ -108,7 +110,7 @@ public class MemberAuthServiceImpl implements MemberAuthService { |
| 108 | 110 | } |
| 109 | 111 | |
| 110 | 112 | @Override |
| 111 | - public String socialLogin(AppAuthSocialLoginReqVO reqVO, String userIp, String userAgent) { | |
| 113 | + public String socialQuickLogin(AppAuthSocialQuickLoginReqVO reqVO, String userIp, String userAgent) { | |
| 112 | 114 | // 使用 code 授权码,进行登录。然后,获得到绑定的用户编号 |
| 113 | 115 | Long userId = socialUserApi.getBindUserId(UserTypeEnum.MEMBER.getValue(), reqVO.getType(), |
| 114 | 116 | reqVO.getCode(), reqVO.getState()); |
| ... | ... | @@ -125,25 +127,19 @@ public class MemberAuthServiceImpl implements MemberAuthService { |
| 125 | 127 | // 创建 LoginUser 对象 |
| 126 | 128 | LoginUser loginUser = AuthConvert.INSTANCE.convert(user); |
| 127 | 129 | |
| 128 | - // 绑定社交用户(更新) | |
| 129 | - socialUserApi.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO)); | |
| 130 | - | |
| 131 | 130 | // 缓存登录用户到 Redis 中,返回 sessionId 编号 |
| 132 | 131 | return createUserSessionAfterLoginSuccess(loginUser, LoginLogTypeEnum.LOGIN_SOCIAL, userIp, userAgent); |
| 133 | 132 | } |
| 134 | 133 | |
| 135 | 134 | @Override |
| 136 | - public String socialLogin2(AppAuthSocialLogin2ReqVO reqVO, String userIp, String userAgent) { | |
| 137 | - // 校验社交平台的认证信息是否正确 | |
| 138 | - socialUserApi.checkSocialUser(reqVO.getType(), reqVO.getCode(), reqVO.getState()); | |
| 139 | - | |
| 135 | + public String socialBindLogin(AppAuthSocialBindLoginReqVO reqVO, String userIp, String userAgent) { | |
| 140 | 136 | // 使用手机号、手机验证码登录 |
| 141 | 137 | AppAuthSmsLoginReqVO loginReqVO = AppAuthSmsLoginReqVO.builder() |
| 142 | 138 | .mobile(reqVO.getMobile()).code(reqVO.getSmsCode()).build(); |
| 143 | 139 | String sessionId = this.smsLogin(loginReqVO, userIp, userAgent); |
| 144 | 140 | LoginUser loginUser = userSessionApi.getLoginUser(sessionId); |
| 145 | 141 | |
| 146 | - // 绑定社交用户(新增) | |
| 142 | + // 绑定社交用户 | |
| 147 | 143 | socialUserApi.bindSocialUser(AuthConvert.INSTANCE.convert(loginUser.getId(), getUserType().getValue(), reqVO)); |
| 148 | 144 | return sessionId; |
| 149 | 145 | } |
| ... | ... | @@ -156,17 +152,6 @@ public class MemberAuthServiceImpl implements MemberAuthService { |
| 156 | 152 | } |
| 157 | 153 | |
| 158 | 154 | @Override |
| 159 | - public void socialBind(Long userId, AppAuthSocialBindReqVO reqVO) { | |
| 160 | - // 绑定社交用户(新增) | |
| 161 | - socialUserApi.bindSocialUser(AuthConvert.INSTANCE.convert(userId, getUserType().getValue(), reqVO)); | |
| 162 | - } | |
| 163 | - | |
| 164 | - @Override | |
| 165 | - public void unbindSocialUser(Long userId, AppAuthSocialUnbindReqVO reqVO) { | |
| 166 | - socialUserApi.unbindSocialUser(AuthConvert.INSTANCE.convert(userId, getUserType().getValue(), reqVO)); | |
| 167 | - } | |
| 168 | - | |
| 169 | - @Override | |
| 170 | 155 | public String getSocialAuthorizeUrl(Integer type, String redirectUri) { |
| 171 | 156 | return socialUserApi.getAuthorizeUrl(type, redirectUri); |
| 172 | 157 | } | ... | ... |
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApi.java
| ... | ... | @@ -38,20 +38,9 @@ public interface SocialUserApi { |
| 38 | 38 | void unbindSocialUser(@Valid SocialUserUnbindReqDTO reqDTO); |
| 39 | 39 | |
| 40 | 40 | /** |
| 41 | - * 校验社交用户的认证信息是否正确 | |
| 42 | - * 如果校验不通过,则抛出 {@link ServiceException} 业务异常 | |
| 43 | - * | |
| 44 | - * @param type 社交平台的类型 | |
| 45 | - * @param code 授权码 | |
| 46 | - * @param state state | |
| 47 | - */ | |
| 48 | - void checkSocialUser(Integer type, String code, String state); | |
| 49 | - | |
| 50 | - /** | |
| 51 | 41 | * 获得社交用户的绑定用户编号 |
| 52 | 42 | * 注意,返回的是 MemberUser 或者 AdminUser 的 id 编号! |
| 53 | - * 该方法会执行和 {@link #checkSocialUser(Integer, String, String)} 一样的逻辑。 | |
| 54 | - * 所以在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常 | |
| 43 | + * 在认证信息不正确的情况下,也会抛出 {@link ServiceException} 业务异常 | |
| 55 | 44 | * |
| 56 | 45 | * @param userType 用户类型 |
| 57 | 46 | * @param type 社交平台的类型 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/social/SocialUserApiImpl.java
| ... | ... | @@ -37,11 +37,6 @@ public class SocialUserApiImpl implements SocialUserApi { |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | @Override |
| 40 | - public void checkSocialUser(Integer type, String code, String state) { | |
| 41 | - socialUserService.authSocialUser(type, code, state); | |
| 42 | - } | |
| 43 | - | |
| 44 | - @Override | |
| 45 | 40 | public Long getBindUserId(Integer userType, Integer type, String code, String state) { |
| 46 | 41 | return socialUserService.getBindUserId(userType, type, code, state); |
| 47 | 42 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/SocialUserController.java
| ... | ... | @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.system.controller.admin.socail; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.CommonResult; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; | |
| 7 | 7 | import cn.iocoder.yudao.module.system.convert.social.SocialUserConvert; |
| 8 | 8 | import cn.iocoder.yudao.module.system.service.social.SocialUserService; |
| 9 | 9 | import io.swagger.annotations.Api; |
| ... | ... | @@ -27,15 +27,15 @@ public class SocialUserController { |
| 27 | 27 | |
| 28 | 28 | @PostMapping("/bind") |
| 29 | 29 | @ApiOperation("社交绑定,使用 code 授权码") |
| 30 | - public CommonResult<Boolean> socialBind(@RequestBody @Valid AuthSocialBindReqVO reqVO) { | |
| 30 | + public CommonResult<Boolean> socialBind(@RequestBody @Valid SocialUserBindReqVO reqVO) { | |
| 31 | 31 | socialUserService.bindSocialUser(SocialUserConvert.INSTANCE.convert(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO)); |
| 32 | 32 | return CommonResult.success(true); |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | @DeleteMapping("/unbind") |
| 36 | 36 | @ApiOperation("取消社交绑定") |
| 37 | - public CommonResult<Boolean> socialUnbind(@RequestBody AuthSocialUnbindReqVO reqVO) { | |
| 38 | - socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getUnionId()); | |
| 37 | + public CommonResult<Boolean> socialUnbind(@RequestBody SocialUserUnbindReqVO reqVO) { | |
| 38 | + socialUserService.unbindSocialUser(getLoginUserId(), UserTypeEnum.ADMIN.getValue(), reqVO.getType(), reqVO.getOpenid()); | |
| 39 | 39 | return CommonResult.success(true); |
| 40 | 40 | } |
| 41 | 41 | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialBindReqVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserBindReqVO.java
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth; | |
| 1 | +package cn.iocoder.yudao.module.system.controller.admin.socail.vo; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| ... | ... | @@ -17,7 +17,7 @@ import javax.validation.constraints.NotNull; |
| 17 | 17 | @NoArgsConstructor |
| 18 | 18 | @AllArgsConstructor |
| 19 | 19 | @Builder |
| 20 | -public class AuthSocialBindReqVO { | |
| 20 | +public class SocialUserBindReqVO { | |
| 21 | 21 | |
| 22 | 22 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") |
| 23 | 23 | @InEnum(SocialTypeEnum.class) | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/auth/vo/auth/AuthSocialUnbindReqVO.java renamed to yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/admin/socail/vo/SocialUserUnbindReqVO.java
| 1 | -package cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth; | |
| 1 | +package cn.iocoder.yudao.module.system.controller.admin.socail.vo; | |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | 4 | import cn.iocoder.yudao.module.system.enums.social.SocialTypeEnum; |
| ... | ... | @@ -12,20 +12,20 @@ import lombok.NoArgsConstructor; |
| 12 | 12 | import javax.validation.constraints.NotEmpty; |
| 13 | 13 | import javax.validation.constraints.NotNull; |
| 14 | 14 | |
| 15 | -@ApiModel("管理后台 - 取消社交绑定 Request VO,使用 code 授权码") | |
| 15 | +@ApiModel("管理后台 - 取消社交绑定 Request VO") | |
| 16 | 16 | @Data |
| 17 | 17 | @NoArgsConstructor |
| 18 | 18 | @AllArgsConstructor |
| 19 | 19 | @Builder |
| 20 | -public class AuthSocialUnbindReqVO { | |
| 20 | +public class SocialUserUnbindReqVO { | |
| 21 | 21 | |
| 22 | 22 | @ApiModelProperty(value = "社交平台的类型", required = true, example = "10", notes = "参见 UserSocialTypeEnum 枚举值") |
| 23 | 23 | @InEnum(SocialTypeEnum.class) |
| 24 | 24 | @NotNull(message = "社交平台的类型不能为空") |
| 25 | 25 | private Integer type; |
| 26 | 26 | |
| 27 | - @ApiModelProperty(value = "社交的全局编号", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 28 | - @NotEmpty(message = "社交的全局编号不能为空") | |
| 29 | - private String unionId; | |
| 27 | + @ApiModelProperty(value = "社交用户的 openid", required = true, example = "IPRmJ0wvBptiPIlGEZiPewGwiEiE") | |
| 28 | + @NotEmpty(message = "社交用户的 openid 不能为空") | |
| 29 | + private String openid; | |
| 30 | 30 | |
| 31 | 31 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/convert/social/SocialUserConvert.java
| ... | ... | @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.system.convert.social; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserBindReqDTO; |
| 4 | 4 | import cn.iocoder.yudao.module.system.api.social.dto.SocialUserUnbindReqDTO; |
| 5 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; | |
| 6 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialUnbindReqVO; | |
| 5 | +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserBindReqVO; | |
| 6 | +import cn.iocoder.yudao.module.system.controller.admin.socail.vo.SocialUserUnbindReqVO; | |
| 7 | 7 | import org.mapstruct.Mapper; |
| 8 | 8 | import org.mapstruct.factory.Mappers; |
| 9 | 9 | |
| ... | ... | @@ -12,8 +12,8 @@ public interface SocialUserConvert { |
| 12 | 12 | |
| 13 | 13 | SocialUserConvert INSTANCE = Mappers.getMapper(SocialUserConvert.class); |
| 14 | 14 | |
| 15 | - SocialUserBindReqDTO convert(Long userId, Integer userType, AuthSocialBindReqVO reqVO); | |
| 15 | + SocialUserBindReqDTO convert(Long userId, Integer userType, SocialUserBindReqVO reqVO); | |
| 16 | 16 | |
| 17 | - SocialUserUnbindReqDTO convert(Long userId, Integer userType, AuthSocialUnbindReqVO reqVO); | |
| 17 | + SocialUserUnbindReqDTO convert(Long userId, Integer userType, SocialUserUnbindReqVO reqVO); | |
| 18 | 18 | |
| 19 | 19 | } | ... | ... |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/auth/AdminAuthServiceImpl.java
| ... | ... | @@ -10,7 +10,6 @@ import cn.iocoder.yudao.framework.security.core.authentication.MultiUsernamePass |
| 10 | 10 | import cn.iocoder.yudao.module.system.api.logger.dto.LoginLogCreateReqDTO; |
| 11 | 11 | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthLoginReqVO; |
| 12 | 12 | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindLoginReqVO; |
| 13 | -import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialBindReqVO; | |
| 14 | 13 | import cn.iocoder.yudao.module.system.controller.admin.auth.vo.auth.AuthSocialQuickLoginReqVO; |
| 15 | 14 | import cn.iocoder.yudao.module.system.convert.auth.AuthConvert; |
| 16 | 15 | import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; | ... | ... |
yudao-ui-admin/src/api/system/socialUser.js
| ... | ... | @@ -14,13 +14,13 @@ export function socialBind(type, code, state) { |
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | // 取消社交绑定 |
| 17 | -export function socialUnbind(type, unionId) { | |
| 17 | +export function socialUnbind(type, openid) { | |
| 18 | 18 | return request({ |
| 19 | 19 | url: '/system/social-user/unbind', |
| 20 | 20 | method: 'delete', |
| 21 | 21 | data: { |
| 22 | 22 | type, |
| 23 | - unionId | |
| 23 | + openid | |
| 24 | 24 | } |
| 25 | 25 | }) |
| 26 | 26 | } | ... | ... |