mirror of
https://github.com/friendica/friendica
synced 2025-05-11 07:04:10 +02:00
Revert "Replace Module::init() with Constructors"
This commit is contained in:
parent
0b6e0566d7
commit
89d6c89b67
43 changed files with 921 additions and 1225 deletions
|
@ -25,11 +25,9 @@ use BaconQrCode\Renderer\Image\SvgImageBackEnd;
|
|||
use BaconQrCode\Renderer\ImageRenderer;
|
||||
use BaconQrCode\Renderer\RendererStyle\RendererStyle;
|
||||
use BaconQrCode\Writer;
|
||||
use Friendica\App\BaseURL;
|
||||
use Friendica\Core\L10n;
|
||||
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\DI;
|
||||
use Friendica\Module\BaseSettings;
|
||||
use Friendica\Module\Security\Login;
|
||||
use PragmaRX\Google2FA\Google2FA;
|
||||
|
@ -41,32 +39,22 @@ use PragmaRX\Google2FA\Google2FA;
|
|||
*/
|
||||
class Verify 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');
|
||||
$verified = $this->pConfig->get(local_user(), '2fa', 'verified');
|
||||
$secret = DI::pConfig()->get(local_user(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(local_user(), '2fa', 'verified');
|
||||
|
||||
if ($secret && $verified) {
|
||||
$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');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -81,17 +69,17 @@ class Verify extends BaseSettings
|
|||
|
||||
$google2fa = new Google2FA();
|
||||
|
||||
$valid = $google2fa->verifyKey($this->pConfig->get(local_user(), '2fa', 'secret'), $_POST['verify_code'] ?? '');
|
||||
$valid = $google2fa->verifyKey(DI::pConfig()->get(local_user(), '2fa', 'secret'), $_POST['verify_code'] ?? '');
|
||||
|
||||
if ($valid) {
|
||||
$this->pConfig->set(local_user(), '2fa', 'verified', true);
|
||||
DI::pConfig()->set(local_user(), '2fa', 'verified', true);
|
||||
Session::set('2fa', true);
|
||||
|
||||
info($this->t('Two-factor authentication successfully activated.'));
|
||||
info(DI::l10n()->t('Two-factor authentication successfully activated.'));
|
||||
|
||||
$this->baseUrl->redirect('settings/2fa');
|
||||
DI::baseUrl()->redirect('settings/2fa');
|
||||
} else {
|
||||
notice($this->t('Invalid code, please retry.'));
|
||||
notice(DI::l10n()->t('Invalid code, please retry.'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -106,7 +94,7 @@ class Verify extends BaseSettings
|
|||
|
||||
$company = 'Friendica';
|
||||
$holder = Session::get('my_address');
|
||||
$secret = $this->pConfig->get(local_user(), '2fa', 'secret');
|
||||
$secret = DI::pConfig()->get(local_user(), '2fa', 'secret');
|
||||
|
||||
$otpauthUrl = (new Google2FA())->getQRCodeUrl($company, $holder, $secret);
|
||||
|
||||
|
@ -120,7 +108,7 @@ class Verify extends BaseSettings
|
|||
|
||||
$shortOtpauthUrl = explode('?', $otpauthUrl)[0];
|
||||
|
||||
$manual_message = $this->t('<p>Or you can submit the authentication settings manually:</p>
|
||||
$manual_message = DI::l10n()->t('<p>Or you can submit the authentication settings manually:</p>
|
||||
<dl>
|
||||
<dt>Issuer</dt>
|
||||
<dd>%s</dd>
|
||||
|
@ -140,18 +128,18 @@ class Verify extends BaseSettings
|
|||
'$form_security_token' => self::getFormSecurityToken('settings_2fa_verify'),
|
||||
'$password_security_token' => self::getFormSecurityToken('settings_2fa_password'),
|
||||
|
||||
'$title' => $this->t('Two-factor code verification'),
|
||||
'$help_label' => $this->t('Help'),
|
||||
'$message' => $this->t('<p>Please scan this QR Code with your authenticator app and submit the provided code.</p>'),
|
||||
'$title' => DI::l10n()->t('Two-factor code verification'),
|
||||
'$help_label' => DI::l10n()->t('Help'),
|
||||
'$message' => DI::l10n()->t('<p>Please scan this QR Code with your authenticator app and submit the provided code.</p>'),
|
||||
'$qrcode_image' => $qrcode_image,
|
||||
'$qrcode_url_message' => $this->t('<p>Or you can open the following URL in your mobile device:</p><p><a href="%s">%s</a></p>', $otpauthUrl, $shortOtpauthUrl),
|
||||
'$qrcode_url_message' => DI::l10n()->t('<p>Or you can open the following URL in your mobile device:</p><p><a href="%s">%s</a></p>', $otpauthUrl, $shortOtpauthUrl),
|
||||
'$manual_message' => $manual_message,
|
||||
'$company' => $company,
|
||||
'$holder' => $holder,
|
||||
'$secret' => $secret,
|
||||
|
||||
'$verify_code' => ['verify_code', $this->t('Please enter a code from your authentication app'), '', '', $this->t('Required'), 'autofocus autocomplete="off" placeholder="000000"'],
|
||||
'$verify_label' => $this->t('Verify code and enable two-factor authentication'),
|
||||
'$verify_code' => ['verify_code', DI::l10n()->t('Please enter a code from your authentication app'), '', '', DI::l10n()->t('Required'), 'autofocus autocomplete="off" placeholder="000000"'],
|
||||
'$verify_label' => DI::l10n()->t('Verify code and enable two-factor authentication'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue