get(local_user(), '2fa', 'secret'); $verified = DI::pConfig()->get(local_user(), '2fa', 'verified'); if ($secret && $verified) { DI::baseUrl()->redirect('settings/2fa'); } if (!self::checkFormSecurityToken('settings_2fa_password', 't')) { notice(L10n::t('Please enter your password to access this page.')); DI::baseUrl()->redirect('settings/2fa'); } } public static function post(array $parameters = []) { if (!local_user()) { return; } if (($_POST['action'] ?? '') == 'verify') { self::checkFormSecurityTokenRedirectOnError('settings/2fa/verify', 'settings_2fa_verify'); $google2fa = new Google2FA(); $valid = $google2fa->verifyKey(DI::pConfig()->get(local_user(), '2fa', 'secret'), $_POST['verify_code'] ?? ''); if ($valid) { PConfig::set(local_user(), '2fa', 'verified', true); Session::set('2fa', true); notice(L10n::t('Two-factor authentication successfully activated.')); DI::baseUrl()->redirect('settings/2fa'); } else { notice(L10n::t('Invalid code, please retry.')); } } } public static function content(array $parameters = []) { if (!local_user()) { return Login::form('settings/2fa/verify'); } parent::content($parameters); $company = 'Friendica'; $holder = Session::get('my_address'); $secret = DI::pConfig()->get(local_user(), '2fa', 'secret'); $otpauthUrl = (new Google2FA())->getQRCodeUrl($company, $holder, $secret); $renderer = (new \BaconQrCode\Renderer\Image\Svg()) ->setHeight(256) ->setWidth(256); $writer = new Writer($renderer); $qrcode_image = str_replace('', '', $writer->writeString($otpauthUrl)); $shortOtpauthUrl = explode('?', $otpauthUrl)[0]; $manual_message = L10n::t('
Or you can submit the authentication settings manually:
Please scan this QR Code with your authenticator app and submit the provided code.
'), '$qrcode_image' => $qrcode_image, '$qrcode_url_message' => L10n::t('Or you can open the following URL in your mobile devicde:
', $otpauthUrl, $shortOtpauthUrl), '$manual_message' => $manual_message, '$company' => $company, '$holder' => $holder, '$secret' => $secret, '$verify_code' => ['verify_code', L10n::t('Please enter a code from your authentication app'), '', '', 'required', 'autofocus placeholder="000000"'], '$verify_label' => L10n::t('Verify code and enable two-factor authentication'), ]); } }