major update

This commit is contained in:
2026-03-04 15:56:58 +01:00
parent 16759a2732
commit 8f4dd5840d
478 changed files with 24313 additions and 8201 deletions

View File

@@ -4,15 +4,22 @@ namespace MintyPHP\Service\User;
use MintyPHP\Http\Request;
use MintyPHP\I18n;
use MintyPHP\Repository\Tenant\TenantRepository;
use MintyPHP\Service\Auth\AuthServicesFactory;
use MintyPHP\Repository\Tenant\UserTenantRepository;
use MintyPHP\Service\Auth\TenantSsoService;
class UserAccessTemplateService
{
public function __construct(
private readonly TenantSsoService $tenantSsoService,
private readonly UserDirectoryGateway $userDirectoryGateway,
private readonly UserTenantRepository $userTenantRepository
) {
}
// Builds locale-aware template variables shared by mail and PDF onboarding output.
public static function buildContext(array $user): array
public function buildContext(array $user): array
{
$locale = self::resolveLocale($user);
$locale = $this->resolveLocale($user);
$name = trim((string) (($user['first_name'] ?? '') . ' ' . ($user['last_name'] ?? '')));
$isGerman = str_starts_with($locale, 'de');
$greeting = $isGerman ? 'Hallo' : 'Hello';
@@ -21,7 +28,7 @@ class UserAccessTemplateService
}
$greeting .= ',';
$loginUrl = self::resolveTenantLoginUrl($user, $locale);
$loginUrl = $this->resolveTenantLoginUrl($user, $locale);
$resetUrl = appUrl(Request::withLocale('password/forgot', $locale));
// Temporarily switch locale so subject translation matches recipient language.
@@ -46,7 +53,7 @@ class UserAccessTemplateService
];
}
public static function resolveLocale(array $user): string
public function resolveLocale(array $user): string
{
// Keep user locale within configured APP_LOCALES; otherwise fallback to app default.
$locale = strtolower(trim((string) ($user['locale'] ?? '')));
@@ -60,9 +67,8 @@ class UserAccessTemplateService
return $locale;
}
private static function resolveTenantLoginUrl(array $user, string $locale): string
private function resolveTenantLoginUrl(array $user, string $locale): string
{
$tenantSsoService = (new AuthServicesFactory())->createTenantSsoService();
$tenantIds = [];
$primaryTenantId = (int) ($user['primary_tenant_id'] ?? 0);
$currentTenantId = (int) ($user['current_tenant_id'] ?? 0);
@@ -77,7 +83,7 @@ class UserAccessTemplateService
if (!$tenantIds && $userId > 0) {
$tenantIds = array_values(array_map(
'intval',
(new UserServicesFactory())->createUserTenantRepository()->listTenantIdsByUserId($userId)
$this->userTenantRepository->listTenantIdsByUserId($userId)
));
}
@@ -85,11 +91,11 @@ class UserAccessTemplateService
if ($tenantId <= 0) {
continue;
}
$tenant = (new TenantRepository())->find($tenantId);
$tenant = $this->userDirectoryGateway->findTenant($tenantId);
if (!$tenant || (string) ($tenant['status'] ?? 'active') !== 'active') {
continue;
}
$tenantSlug = $tenantSsoService->tenantLoginSlug($tenant);
$tenantSlug = $this->tenantSsoService->tenantLoginSlug($tenant);
if ($tenantSlug !== '') {
return appUrl(Request::withLocale('login?tenant=' . rawurlencode($tenantSlug), $locale));
}