refactor: use AccountService for display name in OnboardingService
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package net.siegeln.cameleer.saas.onboarding;
|
package net.siegeln.cameleer.saas.onboarding;
|
||||||
|
|
||||||
|
import net.siegeln.cameleer.saas.account.AccountService;
|
||||||
import net.siegeln.cameleer.saas.identity.LogtoManagementClient;
|
import net.siegeln.cameleer.saas.identity.LogtoManagementClient;
|
||||||
import net.siegeln.cameleer.saas.tenant.TenantEntity;
|
import net.siegeln.cameleer.saas.tenant.TenantEntity;
|
||||||
import net.siegeln.cameleer.saas.tenant.dto.CreateTenantRequest;
|
import net.siegeln.cameleer.saas.tenant.dto.CreateTenantRequest;
|
||||||
@@ -8,7 +9,6 @@ import org.slf4j.Logger;
|
|||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -23,11 +23,14 @@ public class OnboardingService {
|
|||||||
|
|
||||||
private final VendorTenantService vendorTenantService;
|
private final VendorTenantService vendorTenantService;
|
||||||
private final LogtoManagementClient logtoClient;
|
private final LogtoManagementClient logtoClient;
|
||||||
|
private final AccountService accountService;
|
||||||
|
|
||||||
public OnboardingService(VendorTenantService vendorTenantService,
|
public OnboardingService(VendorTenantService vendorTenantService,
|
||||||
LogtoManagementClient logtoClient) {
|
LogtoManagementClient logtoClient,
|
||||||
|
AccountService accountService) {
|
||||||
this.vendorTenantService = vendorTenantService;
|
this.vendorTenantService = vendorTenantService;
|
||||||
this.logtoClient = logtoClient;
|
this.logtoClient = logtoClient;
|
||||||
|
this.accountService = accountService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TenantEntity createTrialTenant(String name, String slug, String logtoUserId) {
|
public TenantEntity createTrialTenant(String name, String slug, String logtoUserId) {
|
||||||
@@ -55,12 +58,12 @@ public class OnboardingService {
|
|||||||
log.info("Added user {} as owner of tenant {}", logtoUserId, slug);
|
log.info("Added user {} as owner of tenant {}", logtoUserId, slug);
|
||||||
|
|
||||||
// Set display name from email if not already set (email-registered users have no name)
|
// Set display name from email if not already set (email-registered users have no name)
|
||||||
var user = logtoClient.getUser(logtoUserId);
|
var profile = accountService.getProfile(logtoUserId);
|
||||||
if (user != null && (user.get("name") == null || String.valueOf(user.get("name")).isBlank())) {
|
if (profile.name() == null || profile.name().isBlank()) {
|
||||||
String email = String.valueOf(user.getOrDefault("primaryEmail", ""));
|
String email = profile.email();
|
||||||
if (!email.isBlank() && email.contains("@")) {
|
if (!email.isBlank() && email.contains("@")) {
|
||||||
String displayName = email.substring(0, email.indexOf('@'));
|
String displayName = email.substring(0, email.indexOf('@'));
|
||||||
logtoClient.updateUserProfile(logtoUserId, Map.of("name", displayName));
|
accountService.updateDisplayName(logtoUserId, displayName);
|
||||||
log.info("Set display name '{}' for user {}", displayName, logtoUserId);
|
log.info("Set display name '{}' for user {}", displayName, logtoUserId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user