feat: mail error sent
Laravel CI-CD / Tests Unitaires (push) Successful in 1m25s Details
Laravel CI-CD / Deploy with Kamal (push) Successful in 1m45s Details

This commit is contained in:
Leon Morival 2026-05-22 13:54:16 +02:00
parent 8ebfd6badf
commit 9fe51e8064
4 changed files with 37 additions and 1 deletions

View File

@ -24,6 +24,7 @@ use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Illuminate\Support\ValidatedInput;
use Illuminate\View\View;
use Throwable;
class AuthController extends Controller
{
@ -43,7 +44,21 @@ class AuthController extends Controller
$user = User::create($userAttributes);
$user->sendEmailVerificationNotification();
try {
$user->sendEmailVerificationNotification();
} catch (Throwable $exception) {
report($exception);
$user->forceDelete();
if ($avatarPath !== null) {
Storage::disk('public')->delete($avatarPath);
}
return response()->json([
'message' => __('api.auth.verification_email_failed'),
], 503);
}
$token = $user->createToken('api', ['user'])->plainTextToken;

View File

@ -10,6 +10,7 @@ return [
'verified' => 'Account verified successfully.',
'verification_sent' => 'Verification email sent.',
'verification_sent_if_unverified' => 'If an unverified account exists for this address, a verification email has been sent.',
'verification_email_failed' => 'Unable to send the verification email right now. Please try again later.',
'password_reset_link_sent' => 'If an account exists for this address, a password reset link has been sent.',
'password_reset' => 'Password reset successfully.',
'logout' => 'Logged out successfully.',

View File

@ -10,6 +10,7 @@ return [
'verified' => 'Compte vérifié avec succès.',
'verification_sent' => 'Email de vérification envoyé.',
'verification_sent_if_unverified' => 'Si un compte non vérifié existe avec cette adresse, un email de vérification vient dêtre envoyé.',
'verification_email_failed' => "Impossible d'envoyer l'email de vérification pour le moment. Réessaie plus tard.",
'password_reset_link_sent' => 'Si un compte existe avec cette adresse, un lien de réinitialisation vient dêtre envoyé.',
'password_reset' => 'Mot de passe réinitialisé avec succès.',
'logout' => 'Déconnecté avec succès.',

View File

@ -56,6 +56,25 @@ it('sends a verification email when a user registers', function () {
Notification::assertSentTo($user, VerifyEmail::class);
});
it('returns a temporary error when the verification email cannot be sent during registration', function () {
Notification::shouldReceive('send')
->once()
->andThrow(new RuntimeException('Mail transport unavailable'));
$this->postJson('/api/auth/register', [
'name' => 'Leon',
'email' => 'leon@example.com',
'password' => 'Motsdfdepasse123*',
'locale' => 'fr-FR',
])
->assertServiceUnavailable()
->assertJsonPath('message', __('api.auth.verification_email_failed'));
$this->assertDatabaseMissing('users', [
'email' => 'leon@example.com',
]);
});
it('uses the custom account verification mailable', function () {
$user = User::factory()->unverified()->create([
'locale' => 'fr',