Move recovery code model to sub-folder

This commit is contained in:
Hypolite Petovan 2019-07-22 07:41:01 -04:00
parent d7fdb42488
commit a149d6ec44
4 changed files with 14 additions and 14 deletions

View File

@ -1,6 +1,6 @@
<?php
namespace Friendica\Model;
namespace Friendica\Model\TwoFactor;
use Friendica\BaseObject;
use Friendica\Database\DBA;
@ -13,7 +13,7 @@ use PragmaRX\Recovery\Recovery;
*
* @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

View File

@ -8,7 +8,7 @@ use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Model\TwoFactorRecoveryCode;
use Friendica\Model\TwoFactor\RecoveryCode;
use Friendica\Model\User;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\Login;
@ -42,7 +42,7 @@ class Index extends BaseSettingsModule
break;
case 'disable':
if ($has_secret) {
TwoFactorRecoveryCode::deleteForUser(local_user());
RecoveryCode::deleteForUser(local_user());
PConfig::delete(local_user(), '2fa', 'secret');
PConfig::delete(local_user(), '2fa', 'verified');
Session::remove('2fa');
@ -94,7 +94,7 @@ class Index extends BaseSettingsModule
'$recovery_codes_title' => L10n::t('Recovery 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>'),
'$action_title' => L10n::t('Actions'),

View File

@ -7,7 +7,7 @@ namespace Friendica\Module\Settings\TwoFactor;
use Friendica\Core\L10n;
use Friendica\Core\PConfig;
use Friendica\Core\Renderer;
use Friendica\Model\TwoFactorRecoveryCode;
use Friendica\Model\TwoFactor\RecoveryCode;
use Friendica\Module\BaseSettingsModule;
use Friendica\Module\Login;
@ -46,7 +46,7 @@ class Recovery extends BaseSettingsModule
self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery');
if ($_POST['action'] == 'regenerate') {
TwoFactorRecoveryCode::regenerateForUser(local_user());
RecoveryCode::regenerateForUser(local_user());
notice(L10n::t('New recovery codes successfully generated.'));
self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
}
@ -61,11 +61,11 @@ class Recovery extends BaseSettingsModule
parent::content();
if (!TwoFactorRecoveryCode::countValidForUser(local_user())) {
TwoFactorRecoveryCode::generateForUser(local_user());
if (!RecoveryCode::countValidForUser(local_user())) {
RecoveryCode::generateForUser(local_user());
}
$recoveryCodes = TwoFactorRecoveryCode::getListForUser(local_user());
$recoveryCodes = RecoveryCode::getListForUser(local_user());
$verified = PConfig::get(local_user(), '2fa', 'verified');

View File

@ -6,7 +6,7 @@ use Friendica\BaseModule;
use Friendica\Core\L10n;
use Friendica\Core\Renderer;
use Friendica\Core\Session;
use Friendica\Model\TwoFactorRecoveryCode;
use Friendica\Model\TwoFactor\RecoveryCode;
/**
* // Page 1a: Recovery code verification
@ -35,10 +35,10 @@ class Recovery extends BaseModule
$recovery_code = defaults($_POST, 'recovery_code', '');
if (TwoFactorRecoveryCode::existsForUser(local_user(), $recovery_code)) {
TwoFactorRecoveryCode::markUsedForUser(local_user(), $recovery_code);
if (RecoveryCode::existsForUser(local_user(), $recovery_code)) {
RecoveryCode::markUsedForUser(local_user(), $recovery_code);
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
Session::setAuthenticatedForUser($a, $a->user, true, true);