$locale, 'subject' => $subject, 'vars' => [ 'app_name' => appTitle(), 'app_logo_url' => appLogoUrlAbsolute(128), 'imprint_url' => appUrl(Request::withLocale('imprint', $locale)), 'privacy_url' => appUrl(Request::withLocale('privacy', $locale)), 'greeting' => $greeting, 'username' => (string) ($user['email'] ?? ''), 'login_url' => $loginUrl, 'reset_url' => $resetUrl, ], ]; } public static function resolveLocale(array $user): string { // Keep user locale within configured APP_LOCALES; otherwise fallback to app default. $locale = strtolower(trim((string) ($user['locale'] ?? ''))); if ($locale === '') { $locale = I18n::$locale ?? I18n::$defaultLocale; } $available = defined('APP_LOCALES') && is_array(APP_LOCALES) ? APP_LOCALES : []; if ($available && !in_array($locale, $available, true)) { $locale = I18n::$defaultLocale; } return $locale; } private static 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); if ($primaryTenantId > 0) { $tenantIds[] = $primaryTenantId; } if ($currentTenantId > 0 && $currentTenantId !== $primaryTenantId) { $tenantIds[] = $currentTenantId; } $userId = (int) ($user['id'] ?? 0); if (!$tenantIds && $userId > 0) { $tenantIds = array_values(array_map( 'intval', (new UserServicesFactory())->createUserTenantRepository()->listTenantIdsByUserId($userId) )); } foreach ($tenantIds as $tenantId) { if ($tenantId <= 0) { continue; } $tenant = (new TenantRepository())->find($tenantId); if (!$tenant || (string) ($tenant['status'] ?? 'active') !== 'active') { continue; } $tenantSlug = $tenantSsoService->tenantLoginSlug($tenant); if ($tenantSlug !== '') { return appUrl(Request::withLocale('login?tenant=' . rawurlencode($tenantSlug), $locale)); } } return appUrl(Request::withLocale('login', $locale)); } }