Revert "Replace Module::init() with Constructors"

This commit is contained in:
Hypolite Petovan 2021-11-19 07:23:23 -05:00 committed by GitHub
parent 0b6e0566d7
commit 89d6c89b67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
43 changed files with 921 additions and 1225 deletions

View file

@ -21,10 +21,8 @@
namespace Friendica\Module\Settings\TwoFactor;
use Friendica\App\BaseURL;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\DI;
use Friendica\Security\TwoFactor\Model\RecoveryCode;
use Friendica\Module\BaseSettings;
use Friendica\Module\Security\Login;
@ -36,31 +34,21 @@ use Friendica\Module\Security\Login;
*/
class Recovery extends BaseSettings
{
/** @var IManagePersonalConfigValues */
protected $pConfig;
/** @var BaseURL */
protected $baseUrl;
public function __construct(IManagePersonalConfigValues $pConfig, BaseURL $baseUrl, L10n $l10n, array $parameters = [])
public function init()
{
parent::__construct($l10n, $parameters);
$this->pConfig = $pConfig;
$this->baseUrl = $baseUrl;
if (!local_user()) {
return;
}
$secret = $this->pConfig->get(local_user(), '2fa', 'secret');
$secret = DI::pConfig()->get(local_user(), '2fa', 'secret');
if (!$secret) {
$this->baseUrl->redirect('settings/2fa');
DI::baseUrl()->redirect('settings/2fa');
}
if (!self::checkFormSecurityToken('settings_2fa_password', 't')) {
notice($this->t('Please enter your password to access this page.'));
$this->baseUrl->redirect('settings/2fa');
notice(DI::l10n()->t('Please enter your password to access this page.'));
DI::baseUrl()->redirect('settings/2fa');
}
}
@ -75,8 +63,8 @@ class Recovery extends BaseSettings
if ($_POST['action'] == 'regenerate') {
RecoveryCode::regenerateForUser(local_user());
info($this->t('New recovery codes successfully generated.'));
$this->baseUrl->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
info(DI::l10n()->t('New recovery codes successfully generated.'));
DI::baseUrl()->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
}
}
}
@ -95,20 +83,20 @@ class Recovery extends BaseSettings
$recoveryCodes = RecoveryCode::getListForUser(local_user());
$verified = $this->pConfig->get(local_user(), '2fa', 'verified');
$verified = DI::pConfig()->get(local_user(), '2fa', 'verified');
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/recovery.tpl'), [
'$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'),
'$password_security_token' => self::getFormSecurityToken('settings_2fa_password'),
'$title' => $this->t('Two-factor recovery codes'),
'$help_label' => $this->t('Help'),
'$message' => $this->t('<p>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.</p><p><strong>Put these in a safe spot!</strong> If you lose your device and dont have the recovery codes you will lose access to your account.</p>'),
'$title' => DI::l10n()->t('Two-factor recovery codes'),
'$help_label' => DI::l10n()->t('Help'),
'$message' => DI::l10n()->t('<p>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.</p><p><strong>Put these in a safe spot!</strong> If you lose your device and dont have the recovery codes you will lose access to your account.</p>'),
'$recovery_codes' => $recoveryCodes,
'$regenerate_message' => $this->t('When you generate new recovery codes, you must copy the new codes. Your old codes wont work anymore.'),
'$regenerate_label' => $this->t('Generate new recovery codes'),
'$regenerate_message' => DI::l10n()->t('When you generate new recovery codes, you must copy the new codes. Your old codes wont work anymore.'),
'$regenerate_label' => DI::l10n()->t('Generate new recovery codes'),
'$verified' => $verified,
'$verify_label' => $this->t('Next: Verification'),
'$verify_label' => DI::l10n()->t('Next: Verification'),
]);
}
}