prefs_twofactor.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * User preferences management page
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. use PhpMyAdmin\Message;
  9. use PhpMyAdmin\TwoFactor;
  10. use PhpMyAdmin\Template;
  11. /**
  12. * Gets some core libraries and displays a top message if required
  13. */
  14. require_once 'libraries/common.inc.php';
  15. require 'libraries/user_preferences.inc.php';
  16. $two_factor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
  17. if (isset($_POST['2fa_remove'])) {
  18. if (! $two_factor->check(true)) {
  19. echo Template::get('prefs_twofactor_confirm')->render([
  20. 'form' => $two_factor->render(),
  21. ]);
  22. exit;
  23. } else {
  24. $two_factor->configure('');
  25. Message::rawNotice(__('Two-factor authentication has been removed.'))->display();
  26. }
  27. } elseif (isset($_POST['2fa_configure'])) {
  28. if (! $two_factor->configure($_POST['2fa_configure'])) {
  29. echo Template::get('prefs_twofactor_configure')->render([
  30. 'form' => $two_factor->setup(),
  31. 'configure' => $_POST['2fa_configure'],
  32. ]);
  33. exit;
  34. } else {
  35. Message::rawNotice(__('Two-factor authentication has been configured.'))->display();
  36. }
  37. }
  38. $backend = $two_factor->backend;
  39. echo Template::get('prefs_twofactor')->render([
  40. 'enabled' => $two_factor->writable,
  41. 'num_backends' => count($two_factor->available),
  42. 'backend_id' => $backend::$id,
  43. 'backend_name' => $backend::getName(),
  44. 'backend_description' => $backend::getDescription(),
  45. 'backends' => $two_factor->getAllBackends(),
  46. 'missing' => $two_factor->getMissingDeps(),
  47. ]);