phpmyadmin/libraries/classes/Controllers/Preferences/TwoFactorController.php
Maurício Meneghini Fauth d89bb277d0
Replace some 'echo' with ResponseRenderer::addHTML() method
Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
2023-08-04 22:07:25 -03:00

82 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpMyAdmin\Controllers\Preferences;
use PhpMyAdmin\ConfigStorage\Relation;
use PhpMyAdmin\Controllers\AbstractController;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
use PhpMyAdmin\TwoFactor;
use function __;
use function count;
use function define;
class TwoFactorController extends AbstractController
{
public function __construct(ResponseRenderer $response, Template $template, private Relation $relation)
{
parent::__construct($response, $template);
}
public function __invoke(ServerRequest $request): void
{
$relationParameters = $this->relation->getRelationParameters();
$this->render('preferences/header', [
'route' => $request->getRoute(),
'is_saved' => $request->hasQueryParam('saved'),
'has_config_storage' => $relationParameters->userPreferencesFeature !== null,
]);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
if ($request->hasBodyParam('2fa_remove')) {
if (! $twoFactor->check(true)) {
$this->render('preferences/two_factor/confirm', ['form' => $twoFactor->render()]);
return;
}
$twoFactor->configure('');
$this->response->addHTML(
Message::rawNotice(__('Two-factor authentication has been removed.'))->getDisplay(),
);
} elseif ($request->hasBodyParam('2fa_configure')) {
if (! $twoFactor->configure($request->getParsedBodyParam('2fa_configure'))) {
$this->render('preferences/two_factor/configure', [
'form' => $twoFactor->setup(),
'configure' => $request->getParsedBodyParam('2fa_configure'),
]);
return;
}
$this->response->addHTML(
Message::rawNotice(__('Two-factor authentication has been configured.'))->getDisplay(),
);
}
$backend = $twoFactor->getBackend();
$this->render('preferences/two_factor/main', [
'enabled' => $twoFactor->isWritable(),
'num_backends' => count($twoFactor->getAvailable()),
'backend_id' => $backend::$id,
'backend_name' => $backend::getName(),
'backend_description' => $backend::getDescription(),
'backends' => $twoFactor->getAllBackends(),
'missing' => $twoFactor->getMissingDeps(),
]);
if ($request->isAjax()) {
$this->response->addJSON('disableNaviSettings', true);
} else {
define('PMA_DISABLE_NAVI_SETTINGS', true);
}
}
}