mirror of
https://git.friendi.ca/friendica/friendica.git
synced 2025-06-11 22:04:26 +02:00
old boot.php functions replaced in src/module (3)
This commit is contained in:
parent
83390d4b00
commit
ae6d67ed1f
22 changed files with 158 additions and 147 deletions
|
@ -22,6 +22,7 @@
|
|||
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;
|
||||
|
@ -35,24 +36,24 @@ class Index extends BaseSettings
|
|||
{
|
||||
protected function post(array $request = [])
|
||||
{
|
||||
if (!local_user()) {
|
||||
if (!Session::getLocalUser()) {
|
||||
return;
|
||||
}
|
||||
|
||||
self::checkFormSecurityTokenRedirectOnError('settings/2fa', 'settings_2fa');
|
||||
|
||||
try {
|
||||
User::getIdFromPasswordAuthentication(local_user(), $_POST['password'] ?? '');
|
||||
User::getIdFromPasswordAuthentication(Session::getLocalUser(), $_POST['password'] ?? '');
|
||||
|
||||
$has_secret = (bool)DI::pConfig()->get(local_user(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(local_user(), '2fa', 'verified');
|
||||
$has_secret = (bool)DI::pConfig()->get(Session::getLocalUser(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(Session::getLocalUser(), '2fa', 'verified');
|
||||
|
||||
switch ($_POST['action'] ?? '') {
|
||||
case 'enable':
|
||||
if (!$has_secret && !$verified) {
|
||||
$Google2FA = new Google2FA();
|
||||
|
||||
DI::pConfig()->set(local_user(), '2fa', 'secret', $Google2FA->generateSecretKey(32));
|
||||
DI::pConfig()->set(Session::getLocalUser(), '2fa', 'secret', $Google2FA->generateSecretKey(32));
|
||||
|
||||
DI::baseUrl()
|
||||
->redirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
|
||||
|
@ -60,9 +61,9 @@ class Index extends BaseSettings
|
|||
break;
|
||||
case 'disable':
|
||||
if ($has_secret) {
|
||||
RecoveryCode::deleteForUser(local_user());
|
||||
DI::pConfig()->delete(local_user(), '2fa', 'secret');
|
||||
DI::pConfig()->delete(local_user(), '2fa', 'verified');
|
||||
RecoveryCode::deleteForUser(Session::getLocalUser());
|
||||
DI::pConfig()->delete(Session::getLocalUser(), '2fa', 'secret');
|
||||
DI::pConfig()->delete(Session::getLocalUser(), '2fa', 'verified');
|
||||
DI::session()->remove('2fa');
|
||||
|
||||
DI::sysmsg()->addInfo(DI::l10n()->t('Two-factor authentication successfully disabled.'));
|
||||
|
@ -103,14 +104,14 @@ class Index extends BaseSettings
|
|||
|
||||
protected function content(array $request = []): string
|
||||
{
|
||||
if (!local_user()) {
|
||||
if (!Session::getLocalUser()) {
|
||||
return Login::form('settings/2fa');
|
||||
}
|
||||
|
||||
parent::content();
|
||||
|
||||
$has_secret = (bool) DI::pConfig()->get(local_user(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(local_user(), '2fa', 'verified');
|
||||
$has_secret = (bool) DI::pConfig()->get(Session::getLocalUser(), '2fa', 'secret');
|
||||
$verified = DI::pConfig()->get(Session::getLocalUser(), '2fa', 'verified');
|
||||
|
||||
return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/index.tpl'), [
|
||||
'$form_security_token' => self::getFormSecurityToken('settings_2fa'),
|
||||
|
@ -128,12 +129,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(local_user()),
|
||||
'$recovery_codes_count' => RecoveryCode::countValidForUser(Session::getLocalUser()),
|
||||
'$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(local_user()),
|
||||
'$app_specific_passwords_count' => AppSpecificPassword::countForUser(Session::getLocalUser()),
|
||||
'$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