From e5ad3a9b8d02d6f798a6cb22c8b0e85fa8eee3e3 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Thu, 6 Oct 2022 21:46:35 +1100 Subject: [PATCH 1/3] Add and use constants for session flashes --- src/Fortify.php | 49 +++++++++++++++++++ ...irmedTwoFactorAuthenticationController.php | 3 +- ...mailVerificationNotificationController.php | 2 +- .../ProfileInformationController.php | 3 +- .../Controllers/RecoveryCodeController.php | 3 +- .../TwoFactorAuthenticationController.php | 5 +- src/Http/Responses/PasswordUpdateResponse.php | 3 +- 7 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/Fortify.php b/src/Fortify.php index 0a3492b5..5e77a974 100644 --- a/src/Fortify.php +++ b/src/Fortify.php @@ -45,6 +45,55 @@ class Fortify */ public static $registersRoutes = true; + /** + * Constant representing a successfully updated password. + * + * @var string + */ + const PASSWORD_UPDATED = 'password-updated'; + + /** + * Constant representing a successfully sent verification reminder. + * + * @var string + */ + const VERIFICATION_LINK_SENT = 'verification-link-sent'; + + /** + * Constant representing a successfully updated user. + * + * @var string + */ + const PROFILE_INFORMATION_UPDATED = 'profile-information-updated'; + + /** + * Constant representing the recovery codes generated response. + * + * @var string + */ + const RECOVERY_CODES_GENERATED = 'recovery-codes-generated'; + + /** + * Constant representing two factor authentication being enabled. + * + * @var string + */ + const TWO_FACTOR_AUTHENTICATION_ENABLED = 'two-factor-authentication-enabled'; + + /** + * Constant representing two factor authentication being disabled. + * + * @var string + */ + const TWO_FACTOR_AUTHENTICATION_DISABLED = 'two-factor-authentication-disabled'; + + /** + * Constant representing two factor authentication being confirmed. + * + * @var string + */ + const TWO_FACTOR_AUTHENTICATION_CONFIRMED = 'two-factor-authentication-confirmed'; + /** * Get the username used for authentication. * diff --git a/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php b/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php index 7f712d3f..789e6a4f 100644 --- a/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php +++ b/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php @@ -5,6 +5,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use Laravel\Fortify\Fortify; use Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication; class ConfirmedTwoFactorAuthenticationController extends Controller @@ -22,6 +23,6 @@ public function store(Request $request, ConfirmTwoFactorAuthentication $confirm) return $request->wantsJson() ? new JsonResponse('', 200) - : back()->with('status', 'two-factor-authentication-confirmed'); + : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_CONFIRMED); } } diff --git a/src/Http/Controllers/EmailVerificationNotificationController.php b/src/Http/Controllers/EmailVerificationNotificationController.php index e3dafac8..c61883f1 100644 --- a/src/Http/Controllers/EmailVerificationNotificationController.php +++ b/src/Http/Controllers/EmailVerificationNotificationController.php @@ -27,6 +27,6 @@ public function store(Request $request) return $request->wantsJson() ? new JsonResponse('', 202) - : back()->with('status', 'verification-link-sent'); + : back()->with('status', Fortify::VERIFICATION_LINK_SENT); } } diff --git a/src/Http/Controllers/ProfileInformationController.php b/src/Http/Controllers/ProfileInformationController.php index 90795b71..cd059bd1 100644 --- a/src/Http/Controllers/ProfileInformationController.php +++ b/src/Http/Controllers/ProfileInformationController.php @@ -5,6 +5,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use Laravel\Fortify\Fortify; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; class ProfileInformationController extends Controller @@ -23,6 +24,6 @@ public function update(Request $request, return $request->wantsJson() ? new JsonResponse('', 200) - : back()->with('status', 'profile-information-updated'); + : back()->with('status', Fortify::PROFILE_INFORMATION_UPDATED); } } diff --git a/src/Http/Controllers/RecoveryCodeController.php b/src/Http/Controllers/RecoveryCodeController.php index 8fda352a..ed168290 100644 --- a/src/Http/Controllers/RecoveryCodeController.php +++ b/src/Http/Controllers/RecoveryCodeController.php @@ -5,6 +5,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use Laravel\Fortify\Fortify; use Laravel\Fortify\Actions\GenerateNewRecoveryCodes; class RecoveryCodeController extends Controller @@ -40,6 +41,6 @@ public function store(Request $request, GenerateNewRecoveryCodes $generate) return $request->wantsJson() ? new JsonResponse('', 200) - : back()->with('status', 'recovery-codes-generated'); + : back()->with('status', Fortify::RECOVERY_CODES_GENERATED); } } diff --git a/src/Http/Controllers/TwoFactorAuthenticationController.php b/src/Http/Controllers/TwoFactorAuthenticationController.php index 23809083..7d7b4c03 100644 --- a/src/Http/Controllers/TwoFactorAuthenticationController.php +++ b/src/Http/Controllers/TwoFactorAuthenticationController.php @@ -5,6 +5,7 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use Laravel\Fortify\Fortify; use Laravel\Fortify\Actions\DisableTwoFactorAuthentication; use Laravel\Fortify\Actions\EnableTwoFactorAuthentication; @@ -23,7 +24,7 @@ public function store(Request $request, EnableTwoFactorAuthentication $enable) return $request->wantsJson() ? new JsonResponse('', 200) - : back()->with('status', 'two-factor-authentication-enabled'); + : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_ENABLED); } /** @@ -39,6 +40,6 @@ public function destroy(Request $request, DisableTwoFactorAuthentication $disabl return $request->wantsJson() ? new JsonResponse('', 200) - : back()->with('status', 'two-factor-authentication-disabled'); + : back()->with('status', Fortify::TWO_FACTOR_AUTHENTICATION_DISABLED); } } diff --git a/src/Http/Responses/PasswordUpdateResponse.php b/src/Http/Responses/PasswordUpdateResponse.php index 48bf33bf..3931ca84 100644 --- a/src/Http/Responses/PasswordUpdateResponse.php +++ b/src/Http/Responses/PasswordUpdateResponse.php @@ -3,6 +3,7 @@ namespace Laravel\Fortify\Http\Responses; use Illuminate\Http\JsonResponse; +use Laravel\Fortify\Fortify; use Laravel\Fortify\Contracts\PasswordUpdateResponse as PasswordUpdateResponseContract; class PasswordUpdateResponse implements PasswordUpdateResponseContract @@ -17,6 +18,6 @@ public function toResponse($request) { return $request->wantsJson() ? new JsonResponse('', 200) - : back()->with('status', 'password-updated'); + : back()->with('status', Fortify::PASSWORD_UPDATED); } } From c19895d23af691dcd3b32e62b5ccc091ee3410c2 Mon Sep 17 00:00:00 2001 From: Dwight Watson Date: Thu, 6 Oct 2022 21:51:14 +1100 Subject: [PATCH 2/3] Apply StyleCI patch --- .../Controllers/ConfirmedTwoFactorAuthenticationController.php | 2 +- src/Http/Controllers/ProfileInformationController.php | 2 +- src/Http/Controllers/RecoveryCodeController.php | 2 +- src/Http/Controllers/TwoFactorAuthenticationController.php | 2 +- src/Http/Responses/PasswordUpdateResponse.php | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php b/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php index 789e6a4f..ec317681 100644 --- a/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php +++ b/src/Http/Controllers/ConfirmedTwoFactorAuthenticationController.php @@ -5,8 +5,8 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Laravel\Fortify\Fortify; use Laravel\Fortify\Actions\ConfirmTwoFactorAuthentication; +use Laravel\Fortify\Fortify; class ConfirmedTwoFactorAuthenticationController extends Controller { diff --git a/src/Http/Controllers/ProfileInformationController.php b/src/Http/Controllers/ProfileInformationController.php index cd059bd1..0f71e049 100644 --- a/src/Http/Controllers/ProfileInformationController.php +++ b/src/Http/Controllers/ProfileInformationController.php @@ -5,8 +5,8 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Laravel\Fortify\Fortify; use Laravel\Fortify\Contracts\UpdatesUserProfileInformation; +use Laravel\Fortify\Fortify; class ProfileInformationController extends Controller { diff --git a/src/Http/Controllers/RecoveryCodeController.php b/src/Http/Controllers/RecoveryCodeController.php index ed168290..50fb5e36 100644 --- a/src/Http/Controllers/RecoveryCodeController.php +++ b/src/Http/Controllers/RecoveryCodeController.php @@ -5,8 +5,8 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Laravel\Fortify\Fortify; use Laravel\Fortify\Actions\GenerateNewRecoveryCodes; +use Laravel\Fortify\Fortify; class RecoveryCodeController extends Controller { diff --git a/src/Http/Controllers/TwoFactorAuthenticationController.php b/src/Http/Controllers/TwoFactorAuthenticationController.php index 7d7b4c03..98df9699 100644 --- a/src/Http/Controllers/TwoFactorAuthenticationController.php +++ b/src/Http/Controllers/TwoFactorAuthenticationController.php @@ -5,9 +5,9 @@ use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Routing\Controller; -use Laravel\Fortify\Fortify; use Laravel\Fortify\Actions\DisableTwoFactorAuthentication; use Laravel\Fortify\Actions\EnableTwoFactorAuthentication; +use Laravel\Fortify\Fortify; class TwoFactorAuthenticationController extends Controller { diff --git a/src/Http/Responses/PasswordUpdateResponse.php b/src/Http/Responses/PasswordUpdateResponse.php index 3931ca84..1acf0b63 100644 --- a/src/Http/Responses/PasswordUpdateResponse.php +++ b/src/Http/Responses/PasswordUpdateResponse.php @@ -3,8 +3,8 @@ namespace Laravel\Fortify\Http\Responses; use Illuminate\Http\JsonResponse; -use Laravel\Fortify\Fortify; use Laravel\Fortify\Contracts\PasswordUpdateResponse as PasswordUpdateResponseContract; +use Laravel\Fortify\Fortify; class PasswordUpdateResponse implements PasswordUpdateResponseContract { From 47a30eaf21327f1bb94deeb5b6ae94e34fd042e5 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 6 Oct 2022 09:07:55 -0500 Subject: [PATCH 3/3] formatting --- src/Fortify.php | 47 +++-------------------------------------------- 1 file changed, 3 insertions(+), 44 deletions(-) diff --git a/src/Fortify.php b/src/Fortify.php index 5e77a974..4203ff3b 100644 --- a/src/Fortify.php +++ b/src/Fortify.php @@ -45,54 +45,13 @@ class Fortify */ public static $registersRoutes = true; - /** - * Constant representing a successfully updated password. - * - * @var string - */ const PASSWORD_UPDATED = 'password-updated'; - - /** - * Constant representing a successfully sent verification reminder. - * - * @var string - */ - const VERIFICATION_LINK_SENT = 'verification-link-sent'; - - /** - * Constant representing a successfully updated user. - * - * @var string - */ const PROFILE_INFORMATION_UPDATED = 'profile-information-updated'; - - /** - * Constant representing the recovery codes generated response. - * - * @var string - */ const RECOVERY_CODES_GENERATED = 'recovery-codes-generated'; - - /** - * Constant representing two factor authentication being enabled. - * - * @var string - */ - const TWO_FACTOR_AUTHENTICATION_ENABLED = 'two-factor-authentication-enabled'; - - /** - * Constant representing two factor authentication being disabled. - * - * @var string - */ - const TWO_FACTOR_AUTHENTICATION_DISABLED = 'two-factor-authentication-disabled'; - - /** - * Constant representing two factor authentication being confirmed. - * - * @var string - */ const TWO_FACTOR_AUTHENTICATION_CONFIRMED = 'two-factor-authentication-confirmed'; + const TWO_FACTOR_AUTHENTICATION_DISABLED = 'two-factor-authentication-disabled'; + const TWO_FACTOR_AUTHENTICATION_ENABLED = 'two-factor-authentication-enabled'; + const VERIFICATION_LINK_SENT = 'verification-link-sent'; /** * Get the username used for authentication.