4 namespace Friendica\Module\Settings\TwoFactor;
7 use Friendica\Core\L10n;
8 use Friendica\Core\PConfig;
9 use Friendica\Core\Renderer;
11 use Friendica\Model\TwoFactor\RecoveryCode;
12 use Friendica\Module\BaseSettingsModule;
13 use Friendica\Module\Security\Login;
16 * // Page 3: 2FA enabled but not verified, show recovery codes
18 * @package Friendica\Module\TwoFactor
20 class Recovery extends BaseSettingsModule
22 public static function init(array $parameters = [])
28 $secret = PConfig::get(local_user(), '2fa', 'secret');
31 DI::app()->internalRedirect('settings/2fa');
34 if (!self::checkFormSecurityToken('settings_2fa_password', 't')) {
35 notice(L10n::t('Please enter your password to access this page.'));
36 DI::app()->internalRedirect('settings/2fa');
40 public static function post(array $parameters = [])
46 if (!empty($_POST['action'])) {
47 self::checkFormSecurityTokenRedirectOnError('settings/2fa/recovery', 'settings_2fa_recovery');
49 if ($_POST['action'] == 'regenerate') {
50 RecoveryCode::regenerateForUser(local_user());
51 notice(L10n::t('New recovery codes successfully generated.'));
52 DI::app()->internalRedirect('settings/2fa/recovery?t=' . self::getFormSecurityToken('settings_2fa_password'));
57 public static function content(array $parameters = [])
60 return Login::form('settings/2fa/recovery');
63 parent::content($parameters);
65 if (!RecoveryCode::countValidForUser(local_user())) {
66 RecoveryCode::generateForUser(local_user());
69 $recoveryCodes = RecoveryCode::getListForUser(local_user());
71 $verified = PConfig::get(local_user(), '2fa', 'verified');
73 return Renderer::replaceMacros(Renderer::getMarkupTemplate('settings/twofactor/recovery.tpl'), [
74 '$form_security_token' => self::getFormSecurityToken('settings_2fa_recovery'),
75 '$password_security_token' => self::getFormSecurityToken('settings_2fa_password'),
77 '$title' => L10n::t('Two-factor recovery codes'),
78 '$help_label' => L10n::t('Help'),
79 '$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>'),
80 '$recovery_codes' => $recoveryCodes,
81 '$regenerate_message' => L10n::t('When you generate new recovery codes, you must copy the new codes. Your old codes won’t work anymore.'),
82 '$regenerate_label' => L10n::t('Generate new recovery codes'),
83 '$verified' => $verified,
84 '$verify_label' => L10n::t('Next: Verification'),