Translated using Weblate (French)
[phpmyadmin.git] / prefs_twofactor.php
blob82033e920fcf80d71d957f3282bd97987286c031
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * User preferences management page
6 * @package PhpMyAdmin
7 */
8 declare(strict_types=1);
10 use PhpMyAdmin\Message;
11 use PhpMyAdmin\Relation;
12 use PhpMyAdmin\Template;
13 use PhpMyAdmin\TwoFactor;
14 use PhpMyAdmin\UserPreferencesHeader;
16 if (! defined('ROOT_PATH')) {
17 define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
20 /**
21 * Gets some core libraries and displays a top message if required
23 require_once ROOT_PATH . 'libraries/common.inc.php';
25 /** @var Template $template */
26 $template = $containerBuilder->get('template');
27 /** @var Relation $relation */
28 $relation = $containerBuilder->get('relation');
29 echo UserPreferencesHeader::getContent($template, $relation);
31 $two_factor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
33 if (isset($_POST['2fa_remove'])) {
34 if (! $two_factor->check(true)) {
35 echo $template->render('preferences/two_factor/confirm', [
36 'form' => $two_factor->render(),
37 ]);
38 exit;
39 } else {
40 $two_factor->configure('');
41 Message::rawNotice(__('Two-factor authentication has been removed.'))->display();
43 } elseif (isset($_POST['2fa_configure'])) {
44 if (! $two_factor->configure($_POST['2fa_configure'])) {
45 echo $template->render('preferences/two_factor/configure', [
46 'form' => $two_factor->setup(),
47 'configure' => $_POST['2fa_configure'],
48 ]);
49 exit;
50 } else {
51 Message::rawNotice(__('Two-factor authentication has been configured.'))->display();
55 $backend = $two_factor->backend;
56 echo $template->render('preferences/two_factor/main', [
57 'enabled' => $two_factor->writable,
58 'num_backends' => count($two_factor->available),
59 'backend_id' => $backend::$id,
60 'backend_name' => $backend::getName(),
61 'backend_description' => $backend::getDescription(),
62 'backends' => $two_factor->getAllBackends(),
63 'missing' => $two_factor->getMissingDeps(),
64 ]);