From bf3ad7f2ed5f87aa995cc8115aaa328de31b2802 Mon Sep 17 00:00:00 2001 From: Sumon Ahmed Date: Thu, 17 Nov 2022 19:44:30 +0600 Subject: [PATCH] Add more Response contract bindings --- .../ProfileInformationUpdatedResponse.php | 10 ++++++++ src/Contracts/RecoveryCodeResponse.php | 10 ++++++++ src/Contracts/TwoFactorConfirmedResponse.php | 10 ++++++++ src/Contracts/TwoFactorDisabledResponse.php | 10 ++++++++ src/Contracts/TwoFactorEnabledResponse.php | 10 ++++++++ src/FortifyServiceProvider.php | 15 ++++++++++++ ...irmedTwoFactorAuthenticationController.php | 9 +++----- .../ProfileInformationController.php | 9 +++----- .../Controllers/RecoveryCodeController.php | 9 +++----- .../TwoFactorAuthenticationController.php | 16 +++++-------- .../ProfileInformationUpdatedResponse.php | 23 +++++++++++++++++++ src/Http/Responses/RecoveryCodeResponse.php | 23 +++++++++++++++++++ .../Responses/TwoFactorConfirmedResponse.php | 23 +++++++++++++++++++ .../Responses/TwoFactorDisabledResponse.php | 23 +++++++++++++++++++ .../Responses/TwoFactorEnabledResponse.php | 23 +++++++++++++++++++ 15 files changed, 195 insertions(+), 28 deletions(-) create mode 100644 src/Contracts/ProfileInformationUpdatedResponse.php create mode 100644 src/Contracts/RecoveryCodeResponse.php create mode 100644 src/Contracts/TwoFactorConfirmedResponse.php create mode 100644 src/Contracts/TwoFactorDisabledResponse.php create mode 100644 src/Contracts/TwoFactorEnabledResponse.php create mode 100644 src/Http/Responses/ProfileInformationUpdatedResponse.php create mode 100644 src/Http/Responses/RecoveryCodeResponse.php create mode 100644 src/Http/Responses/TwoFactorConfirmedResponse.php create mode 100644 src/Http/Responses/TwoFactorDisabledResponse.php create mode 100644 src/Http/Responses/TwoFactorEnabledResponse.php diff --git a/src/Contracts/ProfileInformationUpdatedResponse.php b/src/Contracts/ProfileInformationUpdatedResponse.php new file mode 100644 index 00000000..5649f328 --- /dev/null +++ b/src/Contracts/ProfileInformationUpdatedResponse.php @@ -0,0 +1,10 @@ +app->singleton(FailedTwoFactorLoginResponseContract::class, FailedTwoFactorLoginResponse::class); $this->app->singleton(LockoutResponseContract::class, LockoutResponse::class); $this->app->singleton(LoginResponseContract::class, LoginResponse::class); + $this->app->singleton(TwoFactorConfirmedResponseContract::class, TwoFactorConfirmedResponse::class); + $this->app->singleton(TwoFactorDisabledResponseContract::class, TwoFactorDisabledResponse::class); + $this->app->singleton(TwoFactorEnabledResponseContract::class, TwoFactorEnabledResponse::class); $this->app->singleton(TwoFactorLoginResponseContract::class, TwoFactorLoginResponse::class); $this->app->singleton(LogoutResponseContract::class, LogoutResponse::class); $this->app->singleton(PasswordConfirmedResponseContract::class, PasswordConfirmedResponse::class); $this->app->singleton(PasswordResetResponseContract::class, PasswordResetResponse::class); $this->app->singleton(PasswordUpdateResponseContract::class, PasswordUpdateResponse::class); + $this->app->singleton(ProfileInformationUpdatedResponseContract::class, ProfileInformationUpdatedResponse::class); + $this->app->singleton(RecoveryCodeResponseContract::class, RecoveryCodeResponse::class); $this->app->singleton(RegisterResponseContract::class, RegisterResponse::class); $this->app->singleton(SuccessfulPasswordResetLinkRequestResponseContract::class, SuccessfulPasswordResetLinkRequestResponse::class); $this->app->singleton(VerifyEmailResponseContract::class, VerifyEmailResponse::class); diff --git a/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php b/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php index ec317681..3cd2b51e 100644 --- a/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php +++ b/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php @@ -2,11 +2,10 @@ namespace Laravel\Fortify\Http\Controllers; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication; -use Laravel\Fortify\Fortify; +use Laravel\Fortify\Contracts\TwoFactorConfirmedResponse; class ConfirmedTwoFactorAuthenticationController extends Controller { @@ -15,14 +14,12 @@ class ConfirmedTwoFactorAuthenticationController extends Controller * * @param \Illuminate\Http\Request $request * @param \Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication $confirm - * @return \Symfony\Component\HttpFoundation\Response + * @return \Laravel\Fortify\Contracts\TwoFactorConfirmedResponse */ public function store(Request $request, ConfirmTwoFactorAuthentication $confirm) { $confirm($request->user(), $request->input('code')); - return $request->wantsJson() - ? new JsonResponse('', 200) - : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_CONFIRMED); + return app(TwoFactorConfirmedResponse::class); } } diff --git a/src/Http/Controllers/ProfileInformationController.php b/src/Http/Controllers/ProfileInformationController.php index 0f71e049..6b519956 100644 --- a/src/Http/Controllers/ProfileInformationController.php +++ b/src/Http/Controllers/ProfileInformationController.php @@ -2,11 +2,10 @@ namespace Laravel\Fortify\Http\Controllers; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; -use Laravel\Fortify\Fortify; class ProfileInformationController extends Controller { @@ -15,15 +14,13 @@ class ProfileInformationController extends Controller * * @param \Illuminate\Http\Request $request * @param \Laravel\Fortify\Contracts\UpdatesUserProfileInformation $updater - * @return \Illuminate\Http\Response + * @return \Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse */ public function update(Request $request, UpdatesUserProfileInformation $updater) { $updater->update($request->user(), $request->all()); - return $request->wantsJson() - ? new JsonResponse('', 200) - : back()->with('status', Fortify::PROFILE_INFORMATION_UPDATED); + return app(ProfileInformationUpdatedResponse::class); } } diff --git a/src/Http/Controllers/RecoveryCodeController.php b/src/Http/Controllers/RecoveryCodeController.php index 50fb5e36..3da61310 100644 --- a/src/Http/Controllers/RecoveryCodeController.php +++ b/src/Http/Controllers/RecoveryCodeController.php @@ -2,11 +2,10 @@ namespace Laravel\Fortify\Http\Controllers; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Laravel\Fortify\Actions\GenerateNewRecoveryCodes; -use Laravel\Fortify\Fortify; +use Laravel\Fortify\Contracts\RecoveryCodeResponse; class RecoveryCodeController extends Controller { @@ -33,14 +32,12 @@ public function index(Request $request) * * @param \Illuminate\Http\Request $request * @param \Laravel\Fortify\Actions\GenerateNewRecoveryCodes $generate - * @return \Illuminate\Http\Response + * @return \Laravel\Fortify\Contracts\RecoveryCodeResponse */ public function store(Request $request, GenerateNewRecoveryCodes $generate) { $generate($request->user()); - return $request->wantsJson() - ? new JsonResponse('', 200) - : back()->with('status', Fortify::RECOVERY_CODES_GENERATED); + return app(RecoveryCodeResponse::class); } } diff --git a/src/Http/Controllers/TwoFactorAuthenticationController.php b/src/Http/Controllers/TwoFactorAuthenticationController.php index 98df9699..a4754e96 100644 --- a/src/Http/Controllers/TwoFactorAuthenticationController.php +++ b/src/Http/Controllers/TwoFactorAuthenticationController.php @@ -2,12 +2,12 @@ namespace Laravel\Fortify\Http\Controllers; -use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; use Laravel\Fortify\Actions\DisableTwoFactorAuthentication; use Laravel\Fortify\Actions\EnableTwoFactorAuthentication; -use Laravel\Fortify\Fortify; +use Laravel\Fortify\Contracts\TwoFactorDisabledResponse; +use Laravel\Fortify\Contracts\TwoFactorEnabledResponse; class TwoFactorAuthenticationController extends Controller { @@ -16,15 +16,13 @@ class TwoFactorAuthenticationController extends Controller * * @param \Illuminate\Http\Request $request * @param \Laravel\Fortify\Actions\EnableTwoFactorAuthentication $enable - * @return \Symfony\Component\HttpFoundation\Response + * @return \Laravel\Fortify\Contracts\TwoFactorEnabledResponse */ public function store(Request $request, EnableTwoFactorAuthentication $enable) { $enable($request->user()); - return $request->wantsJson() - ? new JsonResponse('', 200) - : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_ENABLED); + return app(TwoFactorEnabledResponse::class); } /** @@ -32,14 +30,12 @@ public function store(Request $request, EnableTwoFactorAuthentication $enable) * * @param \Illuminate\Http\Request $request * @param \Laravel\Fortify\Actions\DisableTwoFactorAuthentication $disable - * @return \Symfony\Component\HttpFoundation\Response + * @return \Laravel\Fortify\Contracts\TwoFactorDisabledResponse */ public function destroy(Request $request, DisableTwoFactorAuthentication $disable) { $disable($request->user()); - return $request->wantsJson() - ? new JsonResponse('', 200) - : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_DISABLED); + return app(TwoFactorDisabledResponse::class); } } diff --git a/src/Http/Responses/ProfileInformationUpdatedResponse.php b/src/Http/Responses/ProfileInformationUpdatedResponse.php new file mode 100644 index 00000000..86833ca3 --- /dev/null +++ b/src/Http/Responses/ProfileInformationUpdatedResponse.php @@ -0,0 +1,23 @@ +wantsJson() + ? new JsonResponse('', 200) + : back()->with('status', Fortify::PROFILE_INFORMATION_UPDATED); + } +} diff --git a/src/Http/Responses/RecoveryCodeResponse.php b/src/Http/Responses/RecoveryCodeResponse.php new file mode 100644 index 00000000..92a478c7 --- /dev/null +++ b/src/Http/Responses/RecoveryCodeResponse.php @@ -0,0 +1,23 @@ +wantsJson() + ? new JsonResponse('', 200) + : back()->with('status', Fortify::RECOVERY_CODES_GENERATED); + } +} diff --git a/src/Http/Responses/TwoFactorConfirmedResponse.php b/src/Http/Responses/TwoFactorConfirmedResponse.php new file mode 100644 index 00000000..e7ec1257 --- /dev/null +++ b/src/Http/Responses/TwoFactorConfirmedResponse.php @@ -0,0 +1,23 @@ +wantsJson() + ? new JsonResponse('', 200) + : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_CONFIRMED); + } +} diff --git a/src/Http/Responses/TwoFactorDisabledResponse.php b/src/Http/Responses/TwoFactorDisabledResponse.php new file mode 100644 index 00000000..de9c9b6c --- /dev/null +++ b/src/Http/Responses/TwoFactorDisabledResponse.php @@ -0,0 +1,23 @@ +wantsJson() + ? new JsonResponse('', 200) + : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_DISABLED); + } +} diff --git a/src/Http/Responses/TwoFactorEnabledResponse.php b/src/Http/Responses/TwoFactorEnabledResponse.php new file mode 100644 index 00000000..6814a2d7 --- /dev/null +++ b/src/Http/Responses/TwoFactorEnabledResponse.php @@ -0,0 +1,23 @@ +wantsJson() + ? new JsonResponse('', 200) + : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_ENABLED); + } +}