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 Peter Burnett <peterburnett@catalyst-au.net> 30 * @copyright Catalyst IT 31 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 32 */ 33 class user_failed_mfa extends \core\event\base { 34 35 /** 36 * Create instance of event. 37 * 38 * @param stdClass $user the User object of the User who failed MFA authentication. 39 * 40 * @return user_failed_mfa the user_passed_mfa event 41 * 42 * @throws \coding_exception 43 */ 44 public static function user_failed_mfa_event(stdClass $user): user_failed_mfa { 45 // Build debug info string. 46 $factors = \tool_mfa\plugininfo\factor::get_active_user_factor_types(); 47 $debug = ''; 48 $failurereason = get_string('event:failnotenoughfactors', 'tool_mfa'); 49 foreach ($factors as $factor) { 50 $debug .= "<br> Factor {$factor->name} status: {$factor->get_state()}"; 51 if ($factor->get_state() === \tool_mfa\plugininfo\factor::STATE_FAIL) { 52 $failurereason = get_string('event:failfactor', 'tool_mfa'); 53 } else if ($factor->get_state() === \tool_mfa\plugininfo\factor::STATE_LOCKED) { 54 $failurereason = get_string('event:faillockout', 'tool_mfa'); 55 } 56 } 57 58 $data = [ 59 'relateduserid' => null, 60 'context' => \context_user::instance($user->id), 61 'other' => [ 62 'userid' => $user->id, 63 'debug' => $debug, 64 'failurereason' => $failurereason, 65 ], 66 ]; 67 68 return self::create($data); 69 } 70 71 /** 72 * Init method. 73 * 74 * @return void 75 */ 76 protected function init(): void { 77 $this->data['crud'] = 'r'; 78 $this->data['edulevel'] = self::LEVEL_OTHER; 79 } 80 81 /** 82 * Returns description of what happened. 83 * 84 * @return string 85 */ 86 public function get_description(): string { 87 return "The user with id '{$this->other['userid']}' failed authenticating with MFA. 88 <br> Information: {$this->other['failurereason']}{$this->other['debug']}"; 89 } 90 91 /** 92 * Return localised event name. 93 * 94 * @return string 95 * @throws \coding_exception 96 */ 97 public static function get_name(): string { 98 return get_string('event:userfailedmfa', 'tool_mfa'); 99 } 100 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body