134 lines
4.1 KiB
PHP
134 lines
4.1 KiB
PHP
<?php
|
|
|
|
use App\Models\User;
|
|
use App\Models\RegistrationCode;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Validation\Rules;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Volt\Component;
|
|
|
|
new #[Layout('components.layouts.auth')] class extends Component {
|
|
public string $name = '';
|
|
public string $email = '';
|
|
public string $password = '';
|
|
public string $password_confirmation = '';
|
|
protected ?RegistrationCode $registrationCode = null;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->loadRegistrationCode();
|
|
}
|
|
|
|
/**
|
|
* Handle an incoming registration request.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$this->loadRegistrationCode();
|
|
|
|
if (!$this->registrationCode || !$this->registrationCode->isAvailable()) {
|
|
$this->addError('registration_code', __('Registrierungscode fehlt oder ist ungültig. Bitte starten Sie über den QR-Link erneut.'));
|
|
return;
|
|
}
|
|
|
|
$validated = $this->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:' . User::class],
|
|
'password' => ['required', 'string', 'confirmed', Rules\Password::defaults()],
|
|
]);
|
|
|
|
$validated['password'] = Hash::make($validated['password']);
|
|
$validated['display_name'] = $this->registrationCode->name ?? null; // Name aus Registrierungscode übernehmen
|
|
|
|
event(new Registered(($user = User::create($validated))));
|
|
|
|
Auth::login($user);
|
|
|
|
// Registrierungscode als verwendet markieren
|
|
$this->registrationCode->markUsed($user);
|
|
session()->forget(['registration_code_id', 'registration_role']);
|
|
|
|
$this->redirectIntended(route('dashboard', absolute: false), navigate: true);
|
|
}
|
|
|
|
protected function loadRegistrationCode(): void
|
|
{
|
|
if ($this->registrationCode) {
|
|
return;
|
|
}
|
|
|
|
$codeId = session('registration_code_id');
|
|
$role = session('registration_role');
|
|
|
|
if (!$codeId || !$role) {
|
|
return;
|
|
}
|
|
|
|
$this->registrationCode = RegistrationCode::where('id', $codeId)
|
|
->where('role', $role)
|
|
->first();
|
|
}
|
|
}; ?>
|
|
|
|
<div class="flex flex-col gap-6">
|
|
<x-auth-header :title="__('Create an account')" :description="__('Enter your details below to create your account')" />
|
|
|
|
<!-- Session Status -->
|
|
<x-auth-session-status class="text-center" :status="session('status')" />
|
|
|
|
<form wire:submit="register" class="flex flex-col gap-6">
|
|
<!-- Name -->
|
|
<flux:input
|
|
wire:model="name"
|
|
:label="__('Name')"
|
|
type="text"
|
|
required
|
|
autofocus
|
|
autocomplete="name"
|
|
:placeholder="__('Full name')"
|
|
/>
|
|
|
|
<!-- Email Address -->
|
|
<flux:input
|
|
wire:model="email"
|
|
:label="__('Email address')"
|
|
type="email"
|
|
required
|
|
autocomplete="email"
|
|
placeholder="email@example.com"
|
|
/>
|
|
|
|
<!-- Password -->
|
|
<flux:input
|
|
wire:model="password"
|
|
:label="__('Password')"
|
|
type="password"
|
|
required
|
|
autocomplete="new-password"
|
|
:placeholder="__('Password')"
|
|
/>
|
|
|
|
<!-- Confirm Password -->
|
|
<flux:input
|
|
wire:model="password_confirmation"
|
|
:label="__('Confirm password')"
|
|
type="password"
|
|
required
|
|
autocomplete="new-password"
|
|
:placeholder="__('Confirm password')"
|
|
/>
|
|
|
|
<div class="flex items-center justify-end">
|
|
<flux:button type="submit" variant="primary" class="w-full">
|
|
{{ __('Create account') }}
|
|
</flux:button>
|
|
</div>
|
|
</form>
|
|
|
|
<div class="space-x-1 text-center text-sm text-zinc-600 dark:text-zinc-400">
|
|
{{ __('Already have an account?') }}
|
|
<flux:link :href="route('login')" wire:navigate>{{ __('Log in') }}</flux:link>
|
|
</div>
|
|
</div>
|