42 lines
1.2 KiB
PHP
42 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Domain\Identity;
|
|
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class RegisterAccount
|
|
{
|
|
public function register(string $name, string $email, string $password, bool $adult): User
|
|
{
|
|
if (! $adult) {
|
|
throw ValidationException::withMessages([
|
|
'adult' => 'Die Plattform richtet sich an Erwachsene. Ein Konto setzt die Bestätigung voraus.',
|
|
]);
|
|
}
|
|
|
|
return DB::transaction(function () use ($name, $email, $password): User {
|
|
$party = Party::query()->create([
|
|
'type' => PartyType::Person,
|
|
'display_name' => $name,
|
|
]);
|
|
|
|
Profile::query()->create([
|
|
'party_id' => $party->id,
|
|
'display_name' => $name,
|
|
'visibility' => ['display_name' => 'private'],
|
|
]);
|
|
|
|
return User::query()->create([
|
|
'party_id' => $party->id,
|
|
'name' => $name,
|
|
'email' => $email,
|
|
'password' => $password,
|
|
'status' => AccountStatus::Aktiv,
|
|
'confirmed_adult_at' => now(),
|
|
]);
|
|
});
|
|
}
|
|
}
|