add composer-unused, comprehensive docs, and project restructure
- Add icanhazstring/composer-unused as dev dependency for dependency hygiene checks - Add German documentation (docs/) covering architecture, conventions, workflows, and developer checklists - Add API layer (ApiAuth, ApiBootstrap, ApiResponse), audit, scheduler, custom fields, and SSO services - Add Microsoft OIDC SSO, API token management, and user lifecycle features - Add swagger-ui vendor integration and OpenAPI spec - Add production Docker setup and bin/ scripts - Update composer dependencies, config, templates, and frontend assets throughout Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
97
lib/Service/User/UserAccessTemplateService.php
Normal file
97
lib/Service/User/UserAccessTemplateService.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Service\User;
|
||||
|
||||
use MintyPHP\Http\Request;
|
||||
use MintyPHP\I18n;
|
||||
use MintyPHP\Repository\Tenant\TenantRepository;
|
||||
use MintyPHP\Repository\Tenant\UserTenantRepository;
|
||||
use MintyPHP\Service\Auth\TenantSsoService;
|
||||
|
||||
class UserAccessTemplateService
|
||||
{
|
||||
// Builds locale-aware template variables shared by mail and PDF onboarding output.
|
||||
public static function buildContext(array $user): array
|
||||
{
|
||||
$locale = self::resolveLocale($user);
|
||||
$name = trim((string) (($user['first_name'] ?? '') . ' ' . ($user['last_name'] ?? '')));
|
||||
$isGerman = str_starts_with($locale, 'de');
|
||||
$greeting = $isGerman ? 'Hallo' : 'Hello';
|
||||
if ($name !== '') {
|
||||
$greeting .= ' ' . $name;
|
||||
}
|
||||
$greeting .= ',';
|
||||
|
||||
$loginUrl = self::resolveTenantLoginUrl($user, $locale);
|
||||
$resetUrl = appUrl(Request::withLocale('password/forgot', $locale));
|
||||
|
||||
// Temporarily switch locale so subject translation matches recipient language.
|
||||
$previousLocale = I18n::$locale ?? null;
|
||||
I18n::$locale = $locale;
|
||||
$subject = t('Your access details');
|
||||
I18n::$locale = $previousLocale;
|
||||
|
||||
return [
|
||||
'locale' => $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
|
||||
{
|
||||
$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', UserTenantRepository::listTenantIdsByUserId($userId)));
|
||||
}
|
||||
|
||||
foreach ($tenantIds as $tenantId) {
|
||||
if ($tenantId <= 0) {
|
||||
continue;
|
||||
}
|
||||
$tenant = 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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user