Skip to content

Commit

Permalink
update options
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 14, 2020
1 parent f0a6477 commit 2b4fa36
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
14 changes: 9 additions & 5 deletions routes/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
26 changes: 25 additions & 1 deletion src/Features.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -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';
}
}
4 changes: 3 additions & 1 deletion stubs/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@
// Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication(),
Features::twoFactorAuthentication([
'confirmPassword' => true,
]),
],

];

0 comments on commit 2b4fa36

Please sign in to comment.