88import org .apache .commons .lang3 .ObjectUtils ;
99import org .apache .commons .lang3 .RandomStringUtils ;
1010import org .apache .commons .lang3 .StringUtils ;
11+ import org .jetbrains .annotations .NotNull ;
1112import org .lowcoder .domain .asset .model .Asset ;
1213import org .lowcoder .domain .asset .service .AssetService ;
1314import org .lowcoder .domain .authentication .AuthenticationService ;
@@ -197,8 +198,10 @@ public Mono<Boolean> bindEmail(User user, String email) {
197198 .source (AuthSourceConstants .EMAIL )
198199 .name (email )
199200 .rawId (email )
201+ .email (email )
200202 .build ();
201203 user .getConnections ().add (connection );
204+ user .setEmail (email );
202205 return repository .save (user )
203206 .then (Mono .just (true ))
204207 .onErrorResume (throwable -> {
@@ -215,6 +218,7 @@ public Mono<User> addNewConnectionAndReturnUser(String userId, AuthUser authUser
215218 return findById (userId )
216219 .doOnNext (user -> {
217220 user .getConnections ().add (connection );
221+ if (StringUtils .isEmpty (user .getEmail ())) user .setEmail (connection .getEmail ());
218222 user .setActiveAuthId (connection .getAuthId ());
219223
220224 if (AuthSourceConstants .EMAIL .equals (authUser .getSource ())
@@ -360,20 +364,41 @@ public Mono<UserDetail> buildUserDetail(User user, boolean withoutDynamicGroups)
360364 .map (tuple2 -> {
361365 OrgMember orgMember = tuple2 .getT1 ();
362366 List <Map <String , String >> groups = tuple2 .getT2 ();
367+ String activeAuthId = user .getActiveAuthId ();
368+ Optional <Connection > connection = user .getConnections ().stream ().filter (con -> con .getAuthId ().equals (activeAuthId )).findFirst ();
369+ HashMap <String , Object > userAuth = connectionToUserAuthDetail (connection );
363370 return UserDetail .builder ()
364371 .id (user .getId ())
365372 .name (StringUtils .isEmpty (user .getName ())?user .getId ():user .getName ())
366373 .avatarUrl (user .getAvatarUrl ())
367374 .uiLanguage (user .getUiLanguage ())
368- .email (convertEmail ( user .getConnections () ))
375+ .email (user .getEmail ( ))
369376 .ip (ip )
370377 .groups (groups )
371378 .extra (getUserDetailExtra (user , orgMember .getOrgId ()))
379+ .userAuth (userAuth )
372380 .build ();
373381 });
374382 });
375383 }
376384
385+ private static @ NotNull HashMap <String , Object > connectionToUserAuthDetail (Optional <Connection > connection ) {
386+ HashMap <String , Object > userAuth = new HashMap <String , Object >();
387+ if (connection .isPresent ()) {
388+ if (connection .get ().getSource ().equals (AuthSourceConstants .EMAIL )) {
389+ userAuth .put ("jwt" , "" );
390+ userAuth .put ("provider" , AuthSourceConstants .EMAIL );
391+ } else if (connection .get ().getAuthConnectionAuthToken () != null ) {
392+ userAuth .put ("jwt" , connection .get ().getAuthConnectionAuthToken ().getAccessToken ());
393+ userAuth .put ("provider" , connection .get ().getSource ());
394+ } else {
395+ userAuth .put ("jwt" , "" );
396+ userAuth .put ("provider" , connection .get ().getSource ());
397+ }
398+ }
399+ return userAuth ;
400+ }
401+
377402 /**
378403 * In enterprise mode, user can be deleted and then related connections should be released here by appending a timestamp after the source field.
379404 */
0 commit comments