feat: mail error sent
This commit is contained in:
parent
8ebfd6badf
commit
9fe51e8064
|
|
@ -24,6 +24,7 @@ use Illuminate\Support\Facades\Storage;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Illuminate\Support\ValidatedInput;
|
use Illuminate\Support\ValidatedInput;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
use Throwable;
|
||||||
|
|
||||||
class AuthController extends Controller
|
class AuthController extends Controller
|
||||||
{
|
{
|
||||||
|
|
@ -43,7 +44,21 @@ class AuthController extends Controller
|
||||||
|
|
||||||
$user = User::create($userAttributes);
|
$user = User::create($userAttributes);
|
||||||
|
|
||||||
|
try {
|
||||||
$user->sendEmailVerificationNotification();
|
$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;
|
$token = $user->createToken('api', ['user'])->plainTextToken;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ return [
|
||||||
'verified' => 'Account verified successfully.',
|
'verified' => 'Account verified successfully.',
|
||||||
'verification_sent' => 'Verification email sent.',
|
'verification_sent' => 'Verification email sent.',
|
||||||
'verification_sent_if_unverified' => 'If an unverified account exists for this address, a verification email has been 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_link_sent' => 'If an account exists for this address, a password reset link has been sent.',
|
||||||
'password_reset' => 'Password reset successfully.',
|
'password_reset' => 'Password reset successfully.',
|
||||||
'logout' => 'Logged out successfully.',
|
'logout' => 'Logged out successfully.',
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ return [
|
||||||
'verified' => 'Compte vérifié avec succès.',
|
'verified' => 'Compte vérifié avec succès.',
|
||||||
'verification_sent' => 'Email de vérification envoyé.',
|
'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_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_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.',
|
'password_reset' => 'Mot de passe réinitialisé avec succès.',
|
||||||
'logout' => 'Déconnecté avec succès.',
|
'logout' => 'Déconnecté avec succès.',
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,25 @@ it('sends a verification email when a user registers', function () {
|
||||||
Notification::assertSentTo($user, VerifyEmail::class);
|
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 () {
|
it('uses the custom account verification mailable', function () {
|
||||||
$user = User::factory()->unverified()->create([
|
$user = User::factory()->unverified()->create([
|
||||||
'locale' => 'fr',
|
'locale' => 'fr',
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue