4 namespace Friendica\Module\Settings\TwoFactor;
7 use Friendica\Core\L10n;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\Renderer;
10 use Friendica\Model\TwoFactorRecoveryCode;
11 use Friendica\Module\BaseSettingsModule;
12 use Friendica\Module\Login;
15 * // Page 3: 2FA enabled but not verified, show recovery codes
17 * @package Friendica\Module\TwoFactor
19 class Recovery extends BaseSettingsModule
21 public static function init()
27 $secret = PConfig::get(local_user(), '2fa', 'secret');
30 self::getApp()->internalRedirect('settings/2fa');
33 if (!self::checkFormSecurityToken('settings_2fa_password', 't')) {
34 notice(L10n::t('Please enter your password to access this page.'));
35 self::getApp()->internalRedirect('settings/2fa');
39 public static function post()
45 if (!empty($_POST['action'])) {
46 self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery');
48 if ($_POST['action'] == 'regenerate') {
49 TwoFactorRecoveryCode::regenerateForUser(local_user());
50 notice(L10n::t('New recovery codes successfully generated.'));
51 self::getApp()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
56 public static function content()
59 return Login::form('settings/2fa/recovery');
64 if (!TwoFactorRecoveryCode::countValidForUser(local_user())) {
65 TwoFactorRecoveryCode::generateForUser(local_user());
68 $recoveryCodes = TwoFactorRecoveryCode::getListForUser(local_user());
70 $verified = PConfig::get(local_user(), '2fa', 'verified');
72 return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/recovery.tpl'), [
73 '$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'),
74 '$password_security_token' => self::getFormSecurityToken('settings_2fa_password'),
76 '$title' => L10n::t('Two-factor recovery codes'),
77 '$help_label' => L10n::t('Help'),
78 '$message' => L10n::t('<p>Recovery codes can be used to access your account in the event you lose access to your device and cannot receive two-factor authentication codes.</p><p><strong>Put these in a safe spot!</strong> If you lose your device and don’t have the recovery codes you will lose access to your account.</p>'),
79 '$recovery_codes' => $recoveryCodes,
80 '$regenerate_message' => L10n::t('When you generate new recovery codes, you must copy the new codes. Your old codes won’t work anymore.'),
81 '$regenerate_label' => L10n::t('Generate new recovery codes'),
82 '$verified' => $verified,
83 '$verify_label' => L10n::t('Next: Verification'),