diff --git a/app/Event.php b/app/Event.php index 2c4060212..0857e36e1 100644 --- a/app/Event.php +++ b/app/Event.php @@ -416,6 +416,11 @@ public function approve() { $data = ['status' => 'APPROVED', 'approved_by' => auth()->user()->id]; + // Imported/Nova-created events can reach approval without a code, and the email prints it verbatim. + if (empty($this->codeweek_for_all_participation_code)) { + $data['codeweek_for_all_participation_code'] = 'cw'.now()->format('y').'-'.Str::random(5); + } + $this->update($data); if (! empty($this->user_email)) { diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 2a8cfd678..a219ad12b 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -50,7 +50,7 @@ protected function validator(array $data): \Illuminate\Contracts\Validation\Vali return Validator::make($data, [ 'name' => 'required|string|max:255', 'email' => 'required|string|email|max:255|unique:users', - 'password' => ['required', 'string', Password::defaults()], + 'password' => ['required', 'string', 'confirmed', Password::defaults()], 'privacy' => 'required', ]); } diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 9a5735e2d..3999ef9e2 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -84,7 +84,7 @@ class="border-2 border-solid border-dark-blue-200 w-full rounded-full h-12 px-4
- @component('components.validation-errors', ['field'=>'password'])@endcomponent + @component('components.validation-errors', ['field'=>'password_confirmation'])@endcomponent
diff --git a/resources/views/event/show.blade.php b/resources/views/event/show.blade.php index eace7636a..472a4d8a9 100644 --- a/resources/views/event/show.blade.php +++ b/resources/views/event/show.blade.php @@ -75,7 +75,7 @@ @endif
- +
@canany(['edit', 'delete'], $event) diff --git a/tests/Feature/ApproveEventTest.php b/tests/Feature/ApproveEventTest.php index ff6501eb4..bbb036125 100644 --- a/tests/Feature/ApproveEventTest.php +++ b/tests/Feature/ApproveEventTest.php @@ -194,4 +194,31 @@ public function ambassadors_of_right_country_can_see_the_approve_banner(): void ->assertSee('moderate-event'); } + + #[Test] + public function approving_event_without_participation_code_generates_one_for_the_email(): void + { + $this->withExceptionHandling(); + + Mail::fake(); + + $superadmin = \App\User::factory()->create(); + $superadmin->assignRole('super admin'); + + $this->signIn($superadmin); + + $event = \App\Event::factory()->create([ + 'status' => 'PENDING', + 'user_email' => 'foo@bar.com', + 'codeweek_for_all_participation_code' => null, + ]); + + $event->approve(); + + $event = $event->fresh(); + $code = (string) $event->codeweek_for_all_participation_code; + + $this->assertMatchesRegularExpression('/^cw\d{2}-[A-Za-z0-9]+$/', $code); + $this->assertStringContainsString($code, (new EventApproved($event, $event->owner))->render()); + } } diff --git a/tests/Feature/Auth/RegisterPasswordConfirmationTest.php b/tests/Feature/Auth/RegisterPasswordConfirmationTest.php new file mode 100644 index 000000000..3385edc3b --- /dev/null +++ b/tests/Feature/Auth/RegisterPasswordConfirmationTest.php @@ -0,0 +1,25 @@ +post('/register', [ + 'name' => 'Test User', + 'email' => 'mismatch@example.com', + 'password' => 'Xq7!vT2#Lm9@', + 'password_confirmation' => 'Xq7!vT2#Lm9@Z', + 'privacy' => '1', + ]); + + $response->assertSessionHasErrors('password'); + $this->assertDatabaseMissing('users', ['email' => 'mismatch@example.com']); + } +}