Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.3.x will end 7 October 2024 (12 months).
  • Bug fixes for security issues in 4.3.x will end 21 April 2025 (18 months).
  • PHP version: minimum PHP 8.0.0 Note: minimum PHP version has increased since Moodle 4.1. PHP 8.2.x is supported too.
   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  /**
  17   * User preferences page
  18   *
  19   * @package     tool_mfa
  20   * @author      Mikhail Golenkov <golenkovm@gmail.com>
  21   * @copyright   Catalyst IT
  22   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require_once(__DIR__ . '/../../../config.php');
  26  
  27  require_login(null, false);
  28  if (isguestuser()) {
  29      throw new require_login_exception('Guests are not allowed here.');
  30  }
  31  
  32  $action = optional_param('action', '', PARAM_TEXT);
  33  $factorid = optional_param('factorid', 0, PARAM_INT);
  34  
  35  $context = context_user::instance($USER->id);
  36  $PAGE->set_context($context);
  37  $PAGE->set_url('/admin/tool/mfa/user_preferences.php');
  38  $PAGE->set_pagelayout('standard');
  39  $PAGE->set_title(get_string('preferences:header', 'tool_mfa'));
  40  $PAGE->set_cacheable(false);
  41  
  42  if ($node = $PAGE->settingsnav->find('usercurrentsettings', null)) {
  43      $PAGE->navbar->add($node->get_content(), $node->action());
  44  }
  45  $PAGE->navbar->add(get_string('preferences:header', 'tool_mfa'), new \moodle_url('/admin/tool/mfa/user_preferences.php'));
  46  $OUTPUT = $PAGE->get_renderer('tool_mfa');
  47  
  48  echo $OUTPUT->header();
  49  if (!empty($action)) {
  50      if ($factorid != 0) {
  51          $instance = \tool_mfa\plugininfo\factor::get_instance_from_id($factorid);
  52          // Confirm factor is valid for the accessing user.
  53          if ($USER->id == $instance->userid) {
  54              $factor = \tool_mfa\plugininfo\factor::get_factor($instance->factor);
  55              $string = $factor->get_display_name().' - '.$instance->label;
  56              echo $OUTPUT->notification(get_string('factor'.$action, 'tool_mfa', $string), 'notifysuccess');
  57          }
  58      }
  59  }
  60  
  61  echo $OUTPUT->active_factors();
  62  echo $OUTPUT->available_factors();
  63  
  64  $renderer = $PAGE->get_renderer('tool_mfa');
  65  echo $renderer->get_support_link();
  66  
  67  \tool_mfa\manager::display_debug_notification();
  68  
  69  echo $OUTPUT->footer();
  70  
  71  if (!empty($SESSION->tool_mfa_setwantsurl) && $SESSION->tool_mfa_setwantsurl
  72      && \tool_mfa\manager::get_total_weight() >= 100) {
  73      unset($SESSION->wantsurl);
  74  }