mirror of
https://github.com/friendica/friendica
synced 2024-11-10 09:02:53 +00:00
Move recovery code model to sub-folder
This commit is contained in:
parent
d7fdb42488
commit
a149d6ec44
4 changed files with 14 additions and 14 deletions
|
@ -1,6 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Friendica\Model;
|
namespace Friendica\Model\TwoFactor;
|
||||||
|
|
||||||
use Friendica\BaseObject;
|
use Friendica\BaseObject;
|
||||||
use Friendica\Database\DBA;
|
use Friendica\Database\DBA;
|
||||||
|
@ -13,7 +13,7 @@ use PragmaRX\Recovery\Recovery;
|
||||||
*
|
*
|
||||||
* @package Friendica\Model
|
* @package Friendica\Model
|
||||||
*/
|
*/
|
||||||
class TwoFactorRecoveryCode extends BaseObject
|
class RecoveryCode extends BaseObject
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns the number of code the provided users can still use to replace a TOTP code
|
* Returns the number of code the provided users can still use to replace a TOTP code
|
|
@ -8,7 +8,7 @@ use Friendica\Core\L10n;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
use Friendica\Model\TwoFactorRecoveryCode;
|
use Friendica\Model\TwoFactor\RecoveryCode;
|
||||||
use Friendica\Model\User;
|
use Friendica\Model\User;
|
||||||
use Friendica\Module\BaseSettingsModule;
|
use Friendica\Module\BaseSettingsModule;
|
||||||
use Friendica\Module\Login;
|
use Friendica\Module\Login;
|
||||||
|
@ -42,7 +42,7 @@ class Index extends BaseSettingsModule
|
||||||
break;
|
break;
|
||||||
case 'disable':
|
case 'disable':
|
||||||
if ($has_secret) {
|
if ($has_secret) {
|
||||||
TwoFactorRecoveryCode::deleteForUser(local_user());
|
RecoveryCode::deleteForUser(local_user());
|
||||||
PConfig::delete(local_user(), '2fa', 'secret');
|
PConfig::delete(local_user(), '2fa', 'secret');
|
||||||
PConfig::delete(local_user(), '2fa', 'verified');
|
PConfig::delete(local_user(), '2fa', 'verified');
|
||||||
Session::remove('2fa');
|
Session::remove('2fa');
|
||||||
|
@ -94,7 +94,7 @@ class Index extends BaseSettingsModule
|
||||||
|
|
||||||
'$recovery_codes_title' => L10n::t('Recovery codes'),
|
'$recovery_codes_title' => L10n::t('Recovery codes'),
|
||||||
'$recovery_codes_remaining' => L10n::t('Remaining valid codes'),
|
'$recovery_codes_remaining' => L10n::t('Remaining valid codes'),
|
||||||
'$recovery_codes_count' => TwoFactorRecoveryCode::countValidForUser(local_user()),
|
'$recovery_codes_count' => RecoveryCode::countValidForUser(local_user()),
|
||||||
'$recovery_codes_message' => L10n::t('<p>These one-use codes can replace an authenticator app code in case you have lost access to it.</p>'),
|
'$recovery_codes_message' => L10n::t('<p>These one-use codes can replace an authenticator app code in case you have lost access to it.</p>'),
|
||||||
|
|
||||||
'$action_title' => L10n::t('Actions'),
|
'$action_title' => L10n::t('Actions'),
|
||||||
|
|
|
@ -7,7 +7,7 @@ namespace Friendica\Module\Settings\TwoFactor;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\PConfig;
|
use Friendica\Core\PConfig;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Model\TwoFactorRecoveryCode;
|
use Friendica\Model\TwoFactor\RecoveryCode;
|
||||||
use Friendica\Module\BaseSettingsModule;
|
use Friendica\Module\BaseSettingsModule;
|
||||||
use Friendica\Module\Login;
|
use Friendica\Module\Login;
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ class Recovery extends BaseSettingsModule
|
||||||
self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery');
|
self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery');
|
||||||
|
|
||||||
if ($_POST['action'] == 'regenerate') {
|
if ($_POST['action'] == 'regenerate') {
|
||||||
TwoFactorRecoveryCode::regenerateForUser(local_user());
|
RecoveryCode::regenerateForUser(local_user());
|
||||||
notice(L10n::t('New recovery codes successfully generated.'));
|
notice(L10n::t('New recovery codes successfully generated.'));
|
||||||
self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
|
self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
|
||||||
}
|
}
|
||||||
|
@ -61,11 +61,11 @@ class Recovery extends BaseSettingsModule
|
||||||
|
|
||||||
parent::content();
|
parent::content();
|
||||||
|
|
||||||
if (!TwoFactorRecoveryCode::countValidForUser(local_user())) {
|
if (!RecoveryCode::countValidForUser(local_user())) {
|
||||||
TwoFactorRecoveryCode::generateForUser(local_user());
|
RecoveryCode::generateForUser(local_user());
|
||||||
}
|
}
|
||||||
|
|
||||||
$recoveryCodes = TwoFactorRecoveryCode::getListForUser(local_user());
|
$recoveryCodes = RecoveryCode::getListForUser(local_user());
|
||||||
|
|
||||||
$verified = PConfig::get(local_user(), '2fa', 'verified');
|
$verified = PConfig::get(local_user(), '2fa', 'verified');
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use Friendica\BaseModule;
|
||||||
use Friendica\Core\L10n;
|
use Friendica\Core\L10n;
|
||||||
use Friendica\Core\Renderer;
|
use Friendica\Core\Renderer;
|
||||||
use Friendica\Core\Session;
|
use Friendica\Core\Session;
|
||||||
use Friendica\Model\TwoFactorRecoveryCode;
|
use Friendica\Model\TwoFactor\RecoveryCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* // Page 1a: Recovery code verification
|
* // Page 1a: Recovery code verification
|
||||||
|
@ -35,10 +35,10 @@ class Recovery extends BaseModule
|
||||||
|
|
||||||
$recovery_code = defaults($_POST, 'recovery_code', '');
|
$recovery_code = defaults($_POST, 'recovery_code', '');
|
||||||
|
|
||||||
if (TwoFactorRecoveryCode::existsForUser(local_user(), $recovery_code)) {
|
if (RecoveryCode::existsForUser(local_user(), $recovery_code)) {
|
||||||
TwoFactorRecoveryCode::markUsedForUser(local_user(), $recovery_code);
|
RecoveryCode::markUsedForUser(local_user(), $recovery_code);
|
||||||
Session::set('2fa', true);
|
Session::set('2fa', true);
|
||||||
notice(L10n::t('Remaining recovery codes: %d', TwoFactorRecoveryCode::countValidForUser(local_user())));
|
notice(L10n::t('Remaining recovery codes: %d', RecoveryCode::countValidForUser(local_user())));
|
||||||
|
|
||||||
// Resume normal login workflow
|
// Resume normal login workflow
|
||||||
Session::setAuthenticatedForUser($a, $a->user, true, true);
|
Session::setAuthenticatedForUser($a, $a->user, true, true);
|
||||||
|
|
Loading…
Reference in a new issue