UserSession class [5] - Refactor src/Module/ files with DI

This commit is contained in:
Philipp
2022-10-20 22:59:12 +02:00
parent a729f3255d
commit eecc456e0c
78 changed files with 455 additions and 530 deletions

View File

@@ -25,7 +25,6 @@ use Friendica\App;
use Friendica\Core\L10n;
use Friendica\Core\PConfig\Capability\IManagePersonalConfigValues;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\DI;
use Friendica\Module\Response;
use Friendica\Security\TwoFactor\Model\RecoveryCode;
@@ -50,11 +49,11 @@ class Recovery extends BaseSettings
$this->pConfig = $pConfig;
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
$secret = $this->pConfig->get(Session::getLocalUser(), '2fa', 'secret');
$secret = $this->pConfig->get(DI::userSession()->getLocalUserId(), '2fa', 'secret');
if (!$secret) {
$this->baseUrl->redirect('settings/2fa');
@@ -68,7 +67,7 @@ class Recovery extends BaseSettings
protected function post(array $request = [])
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return;
}
@@ -76,7 +75,7 @@ class Recovery extends BaseSettings
self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery');
if ($_POST['action'] == 'regenerate') {
RecoveryCode::regenerateForUser(Session::getLocalUser());
RecoveryCode::regenerateForUser(DI::userSession()->getLocalUserId());
DI::sysmsg()->addInfo($this->t('New recovery codes successfully generated.'));
$this->baseUrl->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
}
@@ -85,19 +84,19 @@ class Recovery extends BaseSettings
protected function content(array $request = []): string
{
if (!Session::getLocalUser()) {
if (!DI::userSession()->getLocalUserId()) {
return Login::form('settings/2fa/recovery');
}
parent::content();
if (!RecoveryCode::countValidForUser(Session::getLocalUser())) {
RecoveryCode::generateForUser(Session::getLocalUser());
if (!RecoveryCode::countValidForUser(DI::userSession()->getLocalUserId())) {
RecoveryCode::generateForUser(DI::userSession()->getLocalUserId());
}
$recoveryCodes = RecoveryCode::getListForUser(Session::getLocalUser());
$recoveryCodes = RecoveryCode::getListForUser(DI::userSession()->getLocalUserId());
$verified = $this->pConfig->get(Session::getLocalUser(), '2fa', 'verified');
$verified = $this->pConfig->get(DI::userSession()->getLocalUserId(), '2fa', 'verified');
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/recovery.tpl'), [
'$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'),