Skip to content

Commit c242a9f

Browse files
committed
fix: 修复绑定部分三方账号错误(暂时修复,后续通过重写 starter 解决)
1 parent 5f66ab5 commit c242a9f

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

continew-webapi/src/main/java/top/continew/admin/controller/system/UserProfileController.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616

1717
package top.continew.admin.controller.system;
1818

19-
import com.xkcoding.justauth.AuthRequestFactory;
19+
import com.xkcoding.justauth.autoconfigure.JustAuthProperties;
2020
import io.swagger.v3.oas.annotations.Operation;
2121
import io.swagger.v3.oas.annotations.Parameter;
2222
import io.swagger.v3.oas.annotations.enums.ParameterIn;
2323
import io.swagger.v3.oas.annotations.tags.Tag;
24+
import jakarta.validation.Valid;
2425
import jakarta.validation.constraints.NotNull;
2526
import lombok.RequiredArgsConstructor;
27+
import me.zhyd.oauth.AuthRequestBuilder;
28+
import me.zhyd.oauth.config.AuthConfig;
2629
import me.zhyd.oauth.model.AuthCallback;
2730
import me.zhyd.oauth.model.AuthResponse;
2831
import me.zhyd.oauth.model.AuthUser;
@@ -41,10 +44,10 @@
4144
import top.continew.admin.system.model.req.user.UserPhoneUpdateReq;
4245
import top.continew.admin.system.model.resp.AvatarResp;
4346
import top.continew.admin.system.model.resp.user.UserSocialBindResp;
44-
import top.continew.admin.system.service.NoticeService;
4547
import top.continew.admin.system.service.UserService;
4648
import top.continew.admin.system.service.UserSocialService;
4749
import top.continew.starter.cache.redisson.util.RedisUtils;
50+
import top.continew.starter.core.exception.BadRequestException;
4851
import top.continew.starter.core.util.ExceptionUtils;
4952
import top.continew.starter.core.validation.ValidationUtils;
5053

@@ -68,8 +71,7 @@ public class UserProfileController {
6871
private static final String CAPTCHA_EXPIRED = "验证码已失效";
6972
private final UserService userService;
7073
private final UserSocialService userSocialService;
71-
private final NoticeService noticeService;
72-
private final AuthRequestFactory authRequestFactory;
74+
private final JustAuthProperties authProperties;
7375

7476
@Operation(summary = "修改头像", description = "用户修改个人头像")
7577
@PatchMapping("/avatar")
@@ -113,7 +115,7 @@ public void updatePhone(@Validated @RequestBody UserPhoneUpdateReq updateReq) {
113115

114116
@Operation(summary = "修改邮箱", description = "修改用户邮箱")
115117
@PatchMapping("/email")
116-
public void updateEmail(@Validated @RequestBody UserEmailUpdateReq updateReq) {
118+
public void updateEmail(@Valid @RequestBody UserEmailUpdateReq updateReq) {
117119
String rawOldPassword = ExceptionUtils.exToNull(() -> SecureUtils.decryptByRsaPrivateKey(updateReq
118120
.getOldPassword()));
119121
ValidationUtils.throwIfBlank(rawOldPassword, DECRYPT_FAILED);
@@ -142,7 +144,7 @@ public List<UserSocialBindResp> listSocialBind() {
142144
@Parameter(name = "source", description = "来源", example = "gitee", in = ParameterIn.PATH)
143145
@PostMapping("/social/{source}")
144146
public void bindSocial(@PathVariable String source, @RequestBody AuthCallback callback) {
145-
AuthRequest authRequest = authRequestFactory.get(source);
147+
AuthRequest authRequest = this.getAuthRequest(source);
146148
AuthResponse<AuthUser> response = authRequest.login(callback);
147149
ValidationUtils.throwIf(!response.ok(), response.getMsg());
148150
AuthUser authUser = response.getData();
@@ -155,4 +157,13 @@ public void bindSocial(@PathVariable String source, @RequestBody AuthCallback ca
155157
public void unbindSocial(@PathVariable String source) {
156158
userSocialService.deleteBySourceAndUserId(source, UserContextHolder.getUserId());
157159
}
160+
161+
private AuthRequest getAuthRequest(String source) {
162+
try {
163+
AuthConfig authConfig = authProperties.getType().get(source.toUpperCase());
164+
return AuthRequestBuilder.builder().source(source).authConfig(authConfig).build();
165+
} catch (Exception e) {
166+
throw new BadRequestException("暂不支持 [%s] 平台账号登录".formatted(source));
167+
}
168+
}
158169
}

0 commit comments

Comments
 (0)