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