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  namespace tool_mfa\event;
  18  
  19  use stdClass;
  20  
  21  /**
  22   * Event for when user successfully passed all MFA factor checks.
  23   *
  24   * @property-read array $other {
  25   *      Extra information about event.
  26   * }
  27   *
  28   * @package     tool_mfa
  29   * @author      Mikhail Golenkov <golenkovm@gmail.com>
  30   * @copyright   Catalyst IT
  31   * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  32   */
  33  class user_passed_mfa extends \core\event\base {
  34  
  35      /**
  36       * Create instance of event.
  37       *
  38       * @param stdClass $user the User object of the User who passed all MFA factor checks.
  39       *
  40       * @return user_passed_mfa the user_passed_mfa event
  41       *
  42       * @throws \coding_exception
  43       */
  44      public static function user_passed_mfa_event(stdClass $user): user_passed_mfa {
  45  
  46          // Build debug info string.
  47          $factors = \tool_mfa\plugininfo\factor::get_active_user_factor_types();
  48          $debug = '';
  49          foreach ($factors as $factor) {
  50              $debug .= "<br> Factor {$factor->name} status: {$factor->get_state()}";
  51          }
  52  
  53          $data = [
  54              'relateduserid' => null,
  55              'context' => \context_user::instance($user->id),
  56              'other' => [
  57                  'userid' => $user->id,
  58                  'debug' => $debug,
  59              ],
  60          ];
  61  
  62          return self::create($data);
  63      }
  64  
  65      /**
  66       * Init method.
  67       *
  68       * @return void
  69       */
  70      protected function init(): void {
  71          $this->data['crud'] = 'r';
  72          $this->data['edulevel'] = self::LEVEL_OTHER;
  73      }
  74  
  75      /**
  76       * Returns description of what happened.
  77       *
  78       * @return string
  79       */
  80      public function get_description(): string {
  81          return "The user with id '{$this->other['userid']}' successfully passed MFA. <br> Information: {$this->other['debug']}";
  82      }
  83  
  84      /**
  85       * Return localised event name.
  86       *
  87       * @return string
  88       * @throws \coding_exception
  89       */
  90      public static function get_name(): string {
  91          return get_string('event:userpassedmfa', 'tool_mfa');
  92      }
  93  }