Skip to content

Commit 5af43d5

Browse files
Added response contract for email verification notification (#489)
* Added response contract for email verification notification * formatting --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 74cd344 commit 5af43d5

4 files changed

+38
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Laravel\Fortify\Contracts;
4+
5+
use Illuminate\Contracts\Support\Responsable;
6+
7+
interface EmailVerificationNotificationSentResponse extends Responsable
8+
{
9+
//
10+
}

src/FortifyServiceProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Support\Facades\Auth;
88
use Illuminate\Support\Facades\Route;
99
use Illuminate\Support\ServiceProvider;
10+
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse as EmailVerificationNotificationSentResponseContract;
1011
use Laravel\Fortify\Contracts\FailedPasswordConfirmationResponse as FailedPasswordConfirmationResponseContract;
1112
use Laravel\Fortify\Contracts\FailedPasswordResetLinkRequestResponse as FailedPasswordResetLinkRequestResponseContract;
1213
use Laravel\Fortify\Contracts\FailedPasswordResetResponse as FailedPasswordResetResponseContract;
@@ -27,6 +28,7 @@
2728
use Laravel\Fortify\Contracts\TwoFactorEnabledResponse as TwoFactorEnabledResponseContract;
2829
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;
2930
use Laravel\Fortify\Contracts\VerifyEmailResponse as VerifyEmailResponseContract;
31+
use Laravel\Fortify\Http\Responses\EmailVerificationNotificationSentResponse;
3032
use Laravel\Fortify\Http\Responses\FailedPasswordConfirmationResponse;
3133
use Laravel\Fortify\Http\Responses\FailedPasswordResetLinkRequestResponse;
3234
use Laravel\Fortify\Http\Responses\FailedPasswordResetResponse;
@@ -93,6 +95,7 @@ protected function registerResponseBindings()
9395
$this->app->singleton(ProfileInformationUpdatedResponseContract::class, ProfileInformationUpdatedResponse::class);
9496
$this->app->singleton(RecoveryCodesGeneratedResponseContract::class, RecoveryCodesGeneratedResponse::class);
9597
$this->app->singleton(RegisterResponseContract::class, RegisterResponse::class);
98+
$this->app->singleton(EmailVerificationNotificationSentResponseContract::class, EmailVerificationNotificationSentResponse::class);
9699
$this->app->singleton(SuccessfulPasswordResetLinkRequestResponseContract::class, SuccessfulPasswordResetLinkRequestResponse::class);
97100
$this->app->singleton(TwoFactorConfirmedResponseContract::class, TwoFactorConfirmedResponse::class);
98101
$this->app->singleton(TwoFactorDisabledResponseContract::class, TwoFactorDisabledResponse::class);

src/Http/Controllers/EmailVerificationNotificationController.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Http\JsonResponse;
66
use Illuminate\Http\Request;
77
use Illuminate\Routing\Controller;
8+
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse;
89
use Laravel\Fortify\Fortify;
910

1011
class EmailVerificationNotificationController extends Controller
@@ -25,8 +26,6 @@ public function store(Request $request)
2526

2627
$request->user()->sendEmailVerificationNotification();
2728

28-
return $request->wantsJson()
29-
? new JsonResponse('', 202)
30-
: back()->with('status', Fortify::VERIFICATION_LINK_SENT);
29+
return app(EmailVerificationNotificationSentResponse::class);
3130
}
3231
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Laravel\Fortify\Http\Responses;
4+
5+
use Illuminate\Http\JsonResponse;
6+
use Laravel\Fortify\Contracts\EmailVerificationNotificationSentResponse as EmailVerificationNotificationSentResponseContract;
7+
use Laravel\Fortify\Fortify;
8+
9+
class EmailVerificationNotificationSentResponse implements EmailVerificationNotificationSentResponseContract
10+
{
11+
/**
12+
* Create an HTTP response that represents the object.
13+
*
14+
* @param \Illuminate\Http\Request $request
15+
* @return \Symfony\Component\HttpFoundation\Response
16+
*/
17+
public function toResponse($request)
18+
{
19+
return $request->wantsJson()
20+
? new JsonResponse('', 202)
21+
: back()->with('status', Fortify::VERIFICATION_LINK_SENT);
22+
}
23+
}

0 commit comments

Comments
 (0)