X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FSettings%2FTwoFactor%2FRecovery.php;h=fb13b8b60d65d11819ea2e63b5181279f14406b6;hb=561aba18e3a230c0912ad9483c6df43cc40e09d6;hp=9f0e74832e6ab6c9fbe4a42e7f97b01b222bd8fc;hpb=8e885f5b971320c1f86075f86ce085cf39c4bd13;p=friendica.git diff --git a/src/Module/Settings/TwoFactor/Recovery.php b/src/Module/Settings/TwoFactor/Recovery.php index 9f0e74832e..fb13b8b60d 100644 --- a/src/Module/Settings/TwoFactor/Recovery.php +++ b/src/Module/Settings/TwoFactor/Recovery.php @@ -1,42 +1,70 @@ . + * + */ namespace Friendica\Module\Settings\TwoFactor; - +use Friendica\App; use Friendica\Core\L10n; -use Friendica\Core\PConfig; +use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues; use Friendica\Core\Renderer; -use Friendica\Model\TwoFactorRecoveryCode; -use Friendica\Module\BaseSettingsModule; -use Friendica\Module\Login; +use Friendica\Module\Response; +use Friendica\Security\TwoFactor\Model\RecoveryCode; +use Friendica\Module\BaseSettings; +use Friendica\Module\Security\Login; +use Friendica\Util\Profiler; +use Psr\Log\LoggerInterface; /** * // Page 3: 2FA enabled but not verified, show recovery codes * * @package Friendica\Module\TwoFactor */ -class Recovery extends BaseSettingsModule +class Recovery extends BaseSettings { - public static function init() + /** @var IManagePersonalConfigValues */ + protected $pConfig; + + public function __construct(L10n $l10n, App\BaseURL $baseUrl, App\Arguments $args, LoggerInterface $logger, Profiler $profiler, Response $response, IManagePersonalConfigValues $pConfig, array $server, array $parameters = []) { + parent::__construct($l10n, $baseUrl, $args, $logger, $profiler, $response, $server, $parameters); + + $this->pConfig = $pConfig; + if (!local_user()) { return; } - $secret = PConfig::get(local_user(), '2fa', 'secret'); + $secret = $this->pConfig->get(local_user(), '2fa', 'secret'); if (!$secret) { - self::getApp()->internalRedirect('settings/2fa'); + $this->baseUrl->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { - notice(L10n::t('Please enter your password to access this page.')); - self::getApp()->internalRedirect('settings/2fa'); + notice($this->t('Please enter your password to access this page.')); + $this->baseUrl->redirect('settings/2fa'); } } - public static function post() + protected function post(array $request = [], array $post = []) { if (!local_user()) { return; @@ -46,14 +74,14 @@ class Recovery extends BaseSettingsModule self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery'); if ($_POST['action'] == 'regenerate') { - TwoFactorRecoveryCode::regenerateForUser(local_user()); - notice(L10n::t('New recovery codes successfully generated.')); - self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); + RecoveryCode::regenerateForUser(local_user()); + info($this->t('New recovery codes successfully generated.')); + $this->baseUrl->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password')); } } } - public static function content() + protected function content(array $request = []): string { if (!local_user()) { return Login::form('settings/2fa/recovery'); @@ -61,26 +89,26 @@ class Recovery extends BaseSettingsModule parent::content(); - if (!TwoFactorRecoveryCode::countValidForUser(local_user())) { - TwoFactorRecoveryCode::generateForUser(local_user()); + if (!RecoveryCode::countValidForUser(local_user())) { + RecoveryCode::generateForUser(local_user()); } - $recoveryCodes = TwoFactorRecoveryCode::getListForUser(local_user()); + $recoveryCodes = RecoveryCode::getListForUser(local_user()); - $verified = PConfig::get(local_user(), '2fa', 'verified'); + $verified = $this->pConfig->get(local_user(), '2fa', 'verified'); return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/recovery.tpl'), [ - '$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'), + '$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'), '$password_security_token' => self::getFormSecurityToken('settings_2fa_password'), - '$title' => L10n::t('Two-factor recovery codes'), - '$help_label' => L10n::t('Help'), - '$message' => L10n::t('

Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes.

Put these in a safe spot! If you lose your device and don’t have the recovery codes you will lose access to your account.

'), - '$recovery_codes' => $recoveryCodes, - '$password' => ['password', L10n::t('Please enter your password for verification:'), '', L10n::t('You need to provide your current password to enable or disable two-factor authentication.'), 'required', 'autofocus'], - '$regenerate_message' => L10n::t('When you generate new recovery codes, you must copy the new codes. Your old codes won’t work anymore.'), - '$regenerate_label' => L10n::t('Generate new recovery codes'), - '$verified' => $verified, - '$verify_label' => L10n::t('Next: Verification'), + + '$title' => $this->t('Two-factor recovery codes'), + '$help_label' => $this->t('Help'), + '$message' => $this->t('

Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes.

Put these in a safe spot! If you lose your device and don’t have the recovery codes you will lose access to your account.

'), + '$recovery_codes' => $recoveryCodes, + '$regenerate_message' => $this->t('When you generate new recovery codes, you must copy the new codes. Your old codes won’t work anymore.'), + '$regenerate_label' => $this->t('Generate new recovery codes'), + '$verified' => $verified, + '$verify_label' => $this->t('Next: Verification'), ]); } }