diff --git a/app/Http/Controllers/ParticipantController.php b/app/Http/Controllers/ParticipantController.php index f435c50..da7892c 100644 --- a/app/Http/Controllers/ParticipantController.php +++ b/app/Http/Controllers/ParticipantController.php @@ -1,10 +1,23 @@ input('password') !== env('ADMIN__PASSWORD')) { + return response()->json(['message' => 'Unauthorized: Wrong password'], 401); + } + + $participant = Participant::create([ + 'user_id' => $id, + 'token' => (string) Str::ulid() + ]); + + return $participant->token; + } } diff --git a/app/Models/Participant.php b/app/Models/Participant.php index 3b610d8..99e7967 100644 --- a/app/Models/Participant.php +++ b/app/Models/Participant.php @@ -63,4 +63,11 @@ class Participant extends Model Log::info($this->user_id); return null; } + + public static function withoutReceivers() + { + return self::whereNotNull('giving_id') + ->whereDoesntHave('receiver'); + } + } diff --git a/database/factories/ParticipantFactory.php b/database/factories/ParticipantFactory.php index 0fbaf4d..ef82083 100644 --- a/database/factories/ParticipantFactory.php +++ b/database/factories/ParticipantFactory.php @@ -25,7 +25,7 @@ class ParticipantFactory extends Factory { return [ 'id' => fake()->unique()->randomNumber(), - 'token' => Str::random(32), + 'token' => (string) Str::ulid(), 'user_id' => fake()->unique()->randomNumber(), ]; } diff --git a/resources/views/livewire/pages/profile.blade.php b/resources/views/livewire/pages/profile.blade.php index 7006b79..0ca48ba 100644 --- a/resources/views/livewire/pages/profile.blade.php +++ b/resources/views/livewire/pages/profile.blade.php @@ -1,26 +1,92 @@ url(); -$participant = computed(function () { - return Participant::findByToken($this->token); +state([ + 'participant' => null, + 'userData' => null, + 'prompt' => '', + 'isEditing' => false, +]); + +rules([ + 'prompt' => 'required|string|min:3', +]); + +mount(function () { + if ($this->token) { + $this->participant = Participant::findByToken($this->token); + + if ($this->participant) { + $this->userData = $this->participant->getUserData(); + $this->prompt = $this->participant->prompt ?? ''; + } + } }); -$userData = computed(function () { - return $this->participant->getUserData(); -}); +$save = function () { + if ($this->participant) { + $this->validate(); + + $this->participant->prompt = $this->prompt; + $this->participant->save(); + $this->isEditing = false; + } +}; + +$cancel = function () { + $this->prompt = $this->participant->prompt ?? ''; + $this->isEditing = false; +}; ?> -@if($this->participant)
{{ $this->participant }}
- @if($this->userData)
- + Your prompt is: {{ $prompt ?: 'No prompt set yet.' }} +
+ + +{{ $participant->giving_id }}
+ @elseif($participant->desperate) +You're in a bind!
+ @else +You haven't been assigned anyone.
+ @endif + @endif