Laravel 11 + Livewire 3/Volt + Alpine.js + Tailwind app for household budget planning, transaction tracking, and financial dashboards. - Multi-tenant households with member invites - Plan: monthly/yearly budget per category with overrides - Suivi: transaction log with running balance (desktop + mobile quick-entry) - Dashboard: budget vs tracked breakdown + Chart.js donuts - Flux: Sankey diagram of income allocation - WCAG 2.1 AA color tokens, dark mode, accessible tables/forms - 50 Pest tests Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
132 lines
4.8 KiB
PHP
132 lines
4.8 KiB
PHP
<?php
|
|
|
|
use App\Models\Household;
|
|
use App\Models\HouseholdInvite;
|
|
use App\Models\User;
|
|
use Illuminate\Auth\Events\Registered;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Validation\Rules;
|
|
use Livewire\Attributes\Layout;
|
|
use Livewire\Volt\Component;
|
|
|
|
new #[Layout('layouts.guest')] class extends Component
|
|
{
|
|
public string $name = '';
|
|
public string $email = '';
|
|
public string $password = '';
|
|
public string $password_confirmation = '';
|
|
public ?string $invite = null;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->invite = request()->query('invite');
|
|
|
|
if ($this->invite) {
|
|
$invite = HouseholdInvite::where('token', $this->invite)->first();
|
|
|
|
if ($invite && ! $invite->isExpired() && ! $invite->isAccepted()) {
|
|
$this->email = $invite->email;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Handle an incoming registration request.
|
|
*/
|
|
public function register(): void
|
|
{
|
|
$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']);
|
|
|
|
$invite = $this->invite
|
|
? HouseholdInvite::where('token', $this->invite)
|
|
->where('email', $validated['email'])
|
|
->whereNull('accepted_at')
|
|
->first()
|
|
: null;
|
|
|
|
$user = DB::transaction(function () use ($validated, $invite) {
|
|
$user = User::create($validated);
|
|
|
|
if ($invite && ! $invite->isExpired()) {
|
|
$user->households()->attach($invite->household_id, ['role' => $invite->role]);
|
|
$invite->update(['accepted_at' => now()]);
|
|
$user->forceFill(['current_household_id' => $invite->household_id])->save();
|
|
} else {
|
|
$household = Household::create([
|
|
'name' => $user->name."'s Household",
|
|
'owner_id' => $user->id,
|
|
]);
|
|
$user->households()->attach($household->id, ['role' => 'owner']);
|
|
$user->forceFill(['current_household_id' => $household->id])->save();
|
|
}
|
|
|
|
return $user;
|
|
});
|
|
|
|
event(new Registered($user));
|
|
|
|
Auth::login($user);
|
|
|
|
$this->redirect(route('dashboard', absolute: false), navigate: true);
|
|
}
|
|
}; ?>
|
|
|
|
<div>
|
|
<form wire:submit="register">
|
|
<!-- Name -->
|
|
<div>
|
|
<x-input-label for="name" :value="__('Name')" />
|
|
<x-text-input wire:model="name" id="name" class="block mt-1 w-full" type="text" name="name" required autofocus autocomplete="name" />
|
|
<x-input-error :messages="$errors->get('name')" class="mt-2" />
|
|
</div>
|
|
|
|
<!-- Email Address -->
|
|
<div class="mt-4">
|
|
<x-input-label for="email" :value="__('Email')" />
|
|
<x-text-input wire:model="email" id="email" class="block mt-1 w-full" type="email" name="email" required autocomplete="username" />
|
|
<x-input-error :messages="$errors->get('email')" class="mt-2" />
|
|
</div>
|
|
|
|
<!-- Password -->
|
|
<div class="mt-4">
|
|
<x-input-label for="password" :value="__('Password')" />
|
|
|
|
<x-text-input wire:model="password" id="password" class="block mt-1 w-full"
|
|
type="password"
|
|
name="password"
|
|
required autocomplete="new-password" />
|
|
|
|
<x-input-error :messages="$errors->get('password')" class="mt-2" />
|
|
</div>
|
|
|
|
<!-- Confirm Password -->
|
|
<div class="mt-4">
|
|
<x-input-label for="password_confirmation" :value="__('Confirm Password')" />
|
|
|
|
<x-text-input wire:model="password_confirmation" id="password_confirmation" class="block mt-1 w-full"
|
|
type="password"
|
|
name="password_confirmation" required autocomplete="new-password" />
|
|
|
|
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
|
|
</div>
|
|
|
|
<div class="flex items-center justify-end mt-4">
|
|
<a class="underline text-sm text-text-muted hover:text-text rounded-md focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-focus-ring focus-visible:ring-offset-surface" href="{{ route('login') }}" wire:navigate>
|
|
{{ __('Already registered?') }}
|
|
</a>
|
|
|
|
<x-primary-button class="ms-4">
|
|
{{ __('Register') }}
|
|
</x-primary-button>
|
|
</div>
|
|
</form>
|
|
</div>
|