mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-11 22:04:26 +02:00
UserSession class [5] - Refactor src/Module/ files with DI
This commit is contained in:
parent
a729f3255d
commit
eecc456e0c
78 changed files with 455 additions and 530 deletions
|
@ -22,7 +22,6 @@
|
|||
namespace Friendica\Module\Settings\TwoFactor;
|
||||
|
||||
use Friendica\Core\Renderer;
|
||||
use Friendica\Core\Session;
|
||||
use Friendica\DI;
|
||||
use Friendica\Network\HTTPException\FoundException;
|
||||
use Friendica\Security\TwoFactor\Model\AppSpecificPassword;
|
||||
|
@ -36,24 +35,24 @@ class Index extends BaseSettings
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('settings/2fa', 'settings_2fa');
|
||||
|
||||
try {
|
||||
User::getIdFromPasswordAuthentication(Session::getLocalUser(), $_POST['password'] ?? '');
|
||||
User::getIdFromPasswordAuthentication(DI::userSession()->getLocalUserId(), $_POST['password'] ?? '');
|
||||
|
||||
$has_secret = (bool)DI::pConfig()->get(Session::getLocalUser(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(Session::getLocalUser(), '2fa', 'verified');
|
||||
$has_secret = (bool)DI::pConfig()->get(DI::userSession()->getLocalUserId(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(DI::userSession()->getLocalUserId(), '2fa', 'verified');
|
||||
|
||||
switch ($_POST['action'] ?? '') {
|
||||
case 'enable':
|
||||
if (!$has_secret && !$verified) {
|
||||
$Google2FA = new Google2FA();
|
||||
|
||||
DI::pConfig()->set(Session::getLocalUser(), '2fa', 'secret', $Google2FA->generateSecretKey(32));
|
||||
DI::pConfig()->set(DI::userSession()->getLocalUserId(), '2fa', 'secret', $Google2FA->generateSecretKey(32));
|
||||
|
||||
DI::baseUrl()
|
||||
->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
|
||||
|
@ -61,9 +60,9 @@ class Index extends BaseSettings
|
|||
break;
|
||||
case 'disable':
|
||||
if ($has_secret) {
|
||||
RecoveryCode::deleteForUser(Session::getLocalUser());
|
||||
DI::pConfig()->delete(Session::getLocalUser(), '2fa', 'secret');
|
||||
DI::pConfig()->delete(Session::getLocalUser(), '2fa', 'verified');
|
||||
RecoveryCode::deleteForUser(DI::userSession()->getLocalUserId());
|
||||
DI::pConfig()->delete(DI::userSession()->getLocalUserId(), '2fa', 'secret');
|
||||
DI::pConfig()->delete(DI::userSession()->getLocalUserId(), '2fa', 'verified');
|
||||
DI::session()->remove('2fa');
|
||||
|
||||
DI::sysmsg()->addInfo(DI::l10n()->t('Two-factor authentication successfully disabled.'));
|
||||
|
@ -104,14 +103,14 @@ class Index extends BaseSettings
|
|||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!Session::getLocalUser()) {
|
||||
if (!DI::userSession()->getLocalUserId()) {
|
||||
return Login::form('settings/2fa');
|
||||
}
|
||||
|
||||
parent::content();
|
||||
|
||||
$has_secret = (bool) DI::pConfig()->get(Session::getLocalUser(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(Session::getLocalUser(), '2fa', 'verified');
|
||||
$has_secret = (bool) DI::pConfig()->get(DI::userSession()->getLocalUserId(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(DI::userSession()->getLocalUserId(), '2fa', 'verified');
|
||||
|
||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/index.tpl'), [
|
||||
'$form_security_token' => self::getFormSecurityToken('settings_2fa'),
|
||||
|
@ -129,12 +128,12 @@ class Index extends BaseSettings
|
|||
|
||||
'$recovery_codes_title' => DI::l10n()->t('Recovery codes'),
|
||||
'$recovery_codes_remaining' => DI::l10n()->t('Remaining valid codes'),
|
||||
'$recovery_codes_count' => RecoveryCode::countValidForUser(Session::getLocalUser()),
|
||||
'$recovery_codes_count' => RecoveryCode::countValidForUser(DI::userSession()->getLocalUserId()),
|
||||
'$recovery_codes_message' => DI::l10n()->t('<p>These one-use codes can replace an authenticator app code in case you have lost access to it.</p>'),
|
||||
|
||||
'$app_specific_passwords_title' => DI::l10n()->t('App-specific passwords'),
|
||||
'$app_specific_passwords_remaining' => DI::l10n()->t('Generated app-specific passwords'),
|
||||
'$app_specific_passwords_count' => AppSpecificPassword::countForUser(Session::getLocalUser()),
|
||||
'$app_specific_passwords_count' => AppSpecificPassword::countForUser(DI::userSession()->getLocalUserId()),
|
||||
'$app_specific_passwords_message' => DI::l10n()->t('<p>These randomly generated passwords allow you to authenticate on apps not supporting two-factor authentication.</p>'),
|
||||
|
||||
'$action_title' => DI::l10n()->t('Actions'),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue