From 2b4fa366377a24705b0ee3525d7c2d456f1fec4b Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Mon, 14 Sep 2020 13:44:58 -0500 Subject: [PATCH] update options --- routes/routes.php | 14 +++++++++----- src/Features.php | 26 +++++++++++++++++++++++++- stubs/fortify.php | 4 +++- 3 files changed, 37 insertions(+), 7 deletions(-) diff --git a/routes/routes.php b/routes/routes.php index b910fcbc..5bb7751e 100644 --- a/routes/routes.php +++ b/routes/routes.php @@ -97,19 +97,23 @@ // Two Factor Authentication... if (Features::enabled(Features::twoFactorAuthentication())) { + $twoFactorMiddleware = Features::optionEnabled(Features::twoFactorAuthentication(), 'confirmPassword') + ? ['auth', 'password.confirm'] + : ['auth']; + Route::post('/user/two-factor-authentication', 'TwoFactorAuthenticationController@store') - ->middleware(['auth', 'password.confirm']); + ->middleware($twoFactorMiddleware); Route::delete('/user/two-factor-authentication', 'TwoFactorAuthenticationController@destroy') - ->middleware(['auth', 'password.confirm']); + ->middleware($twoFactorMiddleware); Route::get('/user/two-factor-qr-code', 'TwoFactorQrCodeController@show') - ->middleware(['auth', 'password.confirm']); + ->middleware($twoFactorMiddleware); Route::get('/user/two-factor-recovery-codes', 'RecoveryCodeController@index') - ->middleware(['auth', 'password.confirm']); + ->middleware($twoFactorMiddleware); Route::post('/user/two-factor-recovery-codes', 'RecoveryCodeController@store') - ->middleware(['auth', 'password.confirm']); + ->middleware($twoFactorMiddleware); } }); diff --git a/src/Features.php b/src/Features.php index 4c163c34..393577ab 100644 --- a/src/Features.php +++ b/src/Features.php @@ -2,8 +2,17 @@ namespace Laravel\Fortify; +use Illuminate\Support\Arr; + class Features { + /** + * The options enabled for a given feature. + * + * @var array + */ + protected static $featureOptions = []; + /** * Determine if the given feature is enabled. * @@ -15,6 +24,19 @@ public static function enabled(string $feature) return in_array($feature, config('fortify.features', [])); } + /** + * Determine if the feature is enabled and has a given option enabled. + * + * @param string $feature + * @param string $option + * @return bool + */ + public static function optionEnabled(string $feature, string $option) + { + return static::enabled($feature) && + Arr::get(static::$featureOptions, $feature.'.'.$option) === true; + } + /** * Determine if the application is using any features that require "profile" management. * @@ -113,8 +135,10 @@ public static function updatePasswords() * * @return string */ - public static function twoFactorAuthentication() + public static function twoFactorAuthentication(array $options = []) { + static::$featureOptions['two-factor-authentication'] = $options; + return 'two-factor-authentication'; } } diff --git a/stubs/fortify.php b/stubs/fortify.php index e9844e03..2d9799b1 100644 --- a/stubs/fortify.php +++ b/stubs/fortify.php @@ -89,7 +89,9 @@ // Features::emailVerification(), Features::updateProfileInformation(), Features::updatePasswords(), - Features::twoFactorAuthentication(), + Features::twoFactorAuthentication([ + 'confirmPassword' => true, + ]), ], ];