Skip to content

Commit

Permalink
Add more Response contract bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
bdsumon4u committed Nov 17, 2022
1 parent 27941f2 commit bf3ad7f
Show file tree
Hide file tree
Showing 15 changed files with 195 additions and 28 deletions.
10 changes: 10 additions & 0 deletions src/Contracts/ProfileInformationUpdatedResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Laravel\Fortify\Contracts;

use Illuminate\Contracts\Support\Responsable;

interface ProfileInformationUpdatedResponse extends Responsable
{
//
}
10 changes: 10 additions & 0 deletions src/Contracts/RecoveryCodeResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Laravel\Fortify\Contracts;

use Illuminate\Contracts\Support\Responsable;

interface RecoveryCodeResponse extends Responsable
{
//
}
10 changes: 10 additions & 0 deletions src/Contracts/TwoFactorConfirmedResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Laravel\Fortify\Contracts;

use Illuminate\Contracts\Support\Responsable;

interface TwoFactorConfirmedResponse extends Responsable
{
//
}
10 changes: 10 additions & 0 deletions src/Contracts/TwoFactorDisabledResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Laravel\Fortify\Contracts;

use Illuminate\Contracts\Support\Responsable;

interface TwoFactorDisabledResponse extends Responsable
{
//
}
10 changes: 10 additions & 0 deletions src/Contracts/TwoFactorEnabledResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Laravel\Fortify\Contracts;

use Illuminate\Contracts\Support\Responsable;

interface TwoFactorEnabledResponse extends Responsable
{
//
}
15 changes: 15 additions & 0 deletions src/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@
use Laravel\Fortify\Contracts\PasswordConfirmedResponse as PasswordConfirmedResponseContract;
use Laravel\Fortify\Contracts\PasswordResetResponse as PasswordResetResponseContract;
use Laravel\Fortify\Contracts\PasswordUpdateResponse as PasswordUpdateResponseContract;
use Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse as ProfileInformationUpdatedResponseContract;
use Laravel\Fortify\Contracts\RecoveryCodeResponse as RecoveryCodeResponseContract;
use Laravel\Fortify\Contracts\RegisterResponse as RegisterResponseContract;
use Laravel\Fortify\Contracts\SuccessfulPasswordResetLinkRequestResponse as SuccessfulPasswordResetLinkRequestResponseContract;
use Laravel\Fortify\Contracts\TwoFactorAuthenticationProvider as TwoFactorAuthenticationProviderContract;
use Laravel\Fortify\Contracts\TwoFactorConfirmedResponse as TwoFactorConfirmedResponseContract;
use Laravel\Fortify\Contracts\TwoFactorDisabledResponse as TwoFactorDisabledResponseContract;
use Laravel\Fortify\Contracts\TwoFactorEnabledResponse as TwoFactorEnabledResponseContract;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;
use Laravel\Fortify\Contracts\VerifyEmailResponse as VerifyEmailResponseContract;
use Laravel\Fortify\Http\Responses\FailedPasswordConfirmationResponse;
Expand All @@ -32,8 +37,13 @@
use Laravel\Fortify\Http\Responses\PasswordConfirmedResponse;
use Laravel\Fortify\Http\Responses\PasswordResetResponse;
use Laravel\Fortify\Http\Responses\PasswordUpdateResponse;
use Laravel\Fortify\Http\Responses\ProfileInformationUpdatedResponse;
use Laravel\Fortify\Http\Responses\RecoveryCodeResponse;
use Laravel\Fortify\Http\Responses\RegisterResponse;
use Laravel\Fortify\Http\Responses\SuccessfulPasswordResetLinkRequestResponse;
use Laravel\Fortify\Http\Responses\TwoFactorConfirmedResponse;
use Laravel\Fortify\Http\Responses\TwoFactorDisabledResponse;
use Laravel\Fortify\Http\Responses\TwoFactorEnabledResponse;
use Laravel\Fortify\Http\Responses\TwoFactorLoginResponse;
use Laravel\Fortify\Http\Responses\VerifyEmailResponse;
use PragmaRX\Google2FA\Google2FA;
Expand Down Expand Up @@ -76,11 +86,16 @@ protected function registerResponseBindings()
$this->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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}
9 changes: 3 additions & 6 deletions src/Http/Controllers/ProfileInformationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}
9 changes: 3 additions & 6 deletions src/Http/Controllers/RecoveryCodeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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);
}
}
16 changes: 6 additions & 10 deletions src/Http/Controllers/TwoFactorAuthenticationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -16,30 +16,26 @@ 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);
}

/**
* Disable two factor authentication for the user.
*
* @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);
}
}
23 changes: 23 additions & 0 deletions src/Http/Responses/ProfileInformationUpdatedResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\ProfileInformationUpdatedResponse as ProfileInformationUpdatedResponseContract;
use Laravel\Fortify\Fortify;

class ProfileInformationUpdatedResponse implements ProfileInformationUpdatedResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::PROFILE_INFORMATION_UPDATED);
}
}
23 changes: 23 additions & 0 deletions src/Http/Responses/RecoveryCodeResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\PasswordUpdateResponse as PasswordUpdateResponseContract;
use Laravel\Fortify\Fortify;

class RecoveryCodeResponse implements PasswordUpdateResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::RECOVERY_CODES_GENERATED);
}
}
23 changes: 23 additions & 0 deletions src/Http/Responses/TwoFactorConfirmedResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\TwoFactorConfirmedResponse as TwoFactorConfirmedResponseContract;
use Laravel\Fortify\Fortify;

class TwoFactorConfirmedResponse implements TwoFactorConfirmedResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_CONFIRMED);
}
}
23 changes: 23 additions & 0 deletions src/Http/Responses/TwoFactorDisabledResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;
use Laravel\Fortify\Fortify;

class TwoFactorDisabledResponse implements TwoFactorLoginResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_DISABLED);
}
}
23 changes: 23 additions & 0 deletions src/Http/Responses/TwoFactorEnabledResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Laravel\Fortify\Http\Responses;

use Illuminate\Http\JsonResponse;
use Laravel\Fortify\Contracts\TwoFactorLoginResponse as TwoFactorLoginResponseContract;
use Laravel\Fortify\Fortify;

class TwoFactorEnabledResponse implements TwoFactorLoginResponseContract
{
/**
* Create an HTTP response that represents the object.
*
* @param \Illuminate\Http\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function toResponse($request)
{
return $request->wantsJson()
? new JsonResponse('', 200)
: back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_ENABLED);
}
}

0 comments on commit bf3ad7f

Please sign in to comment.