presseportale/app/Services/Auth/CustomerAccountProvisioner.php
Kevin Adametz a4184af4fb R0.2: gdpr_consent_at bei allen Registrierungspfaden befuellen (DSGVO)
Feld existierte seit der Migration-2026-Erweiterung, wurde aber nirgends
geschrieben. Jetzt gesetzt bei: Volt-Registrierung (bestaetigte AGB-/
Datenschutz-Checkbox), Magic-Link-Provisioning und Google-OAuth (beide
via CustomerAccountProvisioner, Konto-Anlage nutzerinitiiert).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 07:53:41 +00:00

44 lines
1.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Services\Auth;
use App\Enums\RegistrationType;
use App\Models\User;
/**
* Legt verifizierte Kunden-Accounts an, die über einen vertrauenswürdigen Kanal
* entstehen – Magic-Link an eine hinterlegte E-Mail (ContactAccessService) oder
* Social-Login (SocialAuthService).
*
* Single Source of Truth für das lazy Provisioning: Account direkt aktiv mit
* customer-Rolle, die E-Mail gilt über den bestätigenden Kanal als verifiziert
* (Entscheidung 15.06.2026). Der Name fällt auf die E-Mail zurück, wenn keiner
* bekannt ist.
*/
class CustomerAccountProvisioner
{
public function __construct(private readonly UserRolePermissionSyncService $roleSync) {}
/**
* @param array<string, mixed> $extraAttributes Zusätzliche Spalten beim
* Anlegen (z. B. OAuth-Provider).
*/
public function provisionVerifiedCustomer(string $email, string $name, array $extraAttributes = []): User
{
$user = User::create([
'name' => $name !== '' ? $name : $email,
'email' => $email,
'registration_type' => RegistrationType::Company->value,
'is_active' => true,
// Konto-Anlage ist hier immer nutzerinitiiert (Magic-Link-Anforderung
// bzw. OAuth-Login) – der Zeitpunkt gilt als DSGVO-Einwilligung.
'gdpr_consent_at' => now(),
...$extraAttributes,
]);
$user->forceFill(['email_verified_at' => now()])->save();
$this->roleSync->assignRoleAndSyncPermissions($user, 'customer');
return $user;
}
}