From 52176edc21c5b279998169df651fb160d2373918 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 4 Dec 2026 22:26:30 +0200 Subject: [PATCH] =?UTF-8?q?Registo:=20uma=20recusa=20do=20servidor=20de=20?= =?UTF-8?q?correio=20j=C3=A1=20n=C3=A3o=20d=C3=A1=20erro=20500?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Na produção, a 04/12/2026, o servidor de correio respondeu 550 «User unknown» e o registo, já gravado, terminou em erro 500. A falha de envio do email de confirmação passa a ficar registada e o investidor entra no portal; pode pedir novo envio na página de confirmação. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM --- app/Models/User.php | 16 ++++++++++++++++ tests/Feature/Auth/RegistrationTest.php | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/app/Models/User.php b/app/Models/User.php index fe1fd722..da322ab7 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -13,6 +13,7 @@ use Illuminate\Support\Carbon; use Laravel\Fortify\Contracts\PasskeyUser; use Laravel\Fortify\PasskeyAuthenticatable; use Laravel\Fortify\TwoFactorAuthenticatable; +use Symfony\Component\Mailer\Exception\TransportExceptionInterface; /** * @property int $id @@ -35,6 +36,21 @@ class User extends Authenticatable implements MustVerifyEmail, PasskeyUser /** @use HasFactory */ use HasFactory, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable; + /** + * A mail server that refuses or fails (unknown mailbox, mistyped address, + * server down) must not turn a completed registration into an HTTP 500. + * The account exists; the failure is reported and the investor can ask + * for the email again from the verification page, which uses this path. + */ + public function sendEmailVerificationNotification(): void + { + try { + parent::sendEmailVerificationNotification(); + } catch (TransportExceptionInterface $error) { + report($error); + } + } + /** * Get the attributes that should be cast. * diff --git a/tests/Feature/Auth/RegistrationTest.php b/tests/Feature/Auth/RegistrationTest.php index 4aa36b82..e6e6b3a9 100644 --- a/tests/Feature/Auth/RegistrationTest.php +++ b/tests/Feature/Auth/RegistrationTest.php @@ -36,4 +36,22 @@ class RegistrationTest extends TestCase $this->assertAuthenticated(); $response->assertRedirect(route('dashboard', absolute: false)); } + + public function test_a_refused_verification_email_does_not_turn_registration_into_a_server_error() + { + // Production, 04/12/2026: the mail server answered 550 «User unknown» and the + // registration, already saved, ended in HTTP 500. + config(['mail.default' => 'smtp', 'mail.mailers.smtp.host' => '127.0.0.1', 'mail.mailers.smtp.port' => 1, 'mail.mailers.smtp.timeout' => 2]); + + $response = $this->post(route('register.store'), [ + 'name' => 'Test User', + 'email' => 'unknown-mailbox@example.com', + 'password' => 'password', + 'password_confirmation' => 'password', + ]); + + $this->assertAuthenticated(); + $response->assertRedirect(route('dashboard', absolute: false)); + $this->assertDatabaseHas('users', ['email' => 'unknown-mailbox@example.com', 'email_verified_at' => null]); + } }