8
8
import org .apache .commons .lang3 .ObjectUtils ;
9
9
import org .apache .commons .lang3 .RandomStringUtils ;
10
10
import org .apache .commons .lang3 .StringUtils ;
11
+ import org .jetbrains .annotations .NotNull ;
11
12
import org .lowcoder .domain .asset .model .Asset ;
12
13
import org .lowcoder .domain .asset .service .AssetService ;
13
14
import org .lowcoder .domain .authentication .AuthenticationService ;
@@ -197,8 +198,10 @@ public Mono<Boolean> bindEmail(User user, String email) {
197
198
.source (AuthSourceConstants .EMAIL )
198
199
.name (email )
199
200
.rawId (email )
201
+ .email (email )
200
202
.build ();
201
203
user .getConnections ().add (connection );
204
+ user .setEmail (email );
202
205
return repository .save (user )
203
206
.then (Mono .just (true ))
204
207
.onErrorResume (throwable -> {
@@ -215,6 +218,7 @@ public Mono<User> addNewConnectionAndReturnUser(String userId, AuthUser authUser
215
218
return findById (userId )
216
219
.doOnNext (user -> {
217
220
user .getConnections ().add (connection );
221
+ if (StringUtils .isEmpty (user .getEmail ())) user .setEmail (connection .getEmail ());
218
222
user .setActiveAuthId (connection .getAuthId ());
219
223
220
224
if (AuthSourceConstants .EMAIL .equals (authUser .getSource ())
@@ -360,20 +364,41 @@ public Mono<UserDetail> buildUserDetail(User user, boolean withoutDynamicGroups)
360
364
.map (tuple2 -> {
361
365
OrgMember orgMember = tuple2 .getT1 ();
362
366
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 );
363
370
return UserDetail .builder ()
364
371
.id (user .getId ())
365
372
.name (StringUtils .isEmpty (user .getName ())?user .getId ():user .getName ())
366
373
.avatarUrl (user .getAvatarUrl ())
367
374
.uiLanguage (user .getUiLanguage ())
368
- .email (convertEmail ( user .getConnections () ))
375
+ .email (user .getEmail ( ))
369
376
.ip (ip )
370
377
.groups (groups )
371
378
.extra (getUserDetailExtra (user , orgMember .getOrgId ()))
379
+ .userAuth (userAuth )
372
380
.build ();
373
381
});
374
382
});
375
383
}
376
384
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
+
377
402
/**
378
403
* In enterprise mode, user can be deleted and then related connections should be released here by appending a timestamp after the source field.
379
404
*/
0 commit comments