Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   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  /**
  18   * Web service login failed event.
  19   *
  20   * @package    core
  21   * @copyright  2013 Frédéric Massart
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core\event;
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Web service login failed event class.
  30   *
  31   * @property-read array $other {
  32   *      Extra information about event.
  33   *
  34   *      - string method: authentication method.
  35   *      - string reason: failure reason.
  36   *      - string tokenid: id of token.
  37   * }
  38   *
  39   * @package    core
  40   * @since      Moodle 2.6
  41   * @copyright  2013 Frédéric Massart
  42   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class webservice_login_failed extends base {
  45  
  46      /**
  47       * Legacy log data.
  48       *
  49       * @var null|array
  50       */
  51      protected $legacylogdata;
  52  
  53      /**
  54       * Returns description of what happened.
  55       *
  56       * @return string
  57       */
  58      public function get_description() {
  59          return "Web service authentication failed with code: \"{$this->other['reason']}\".";
  60      }
  61  
  62      /**
  63       * Return the legacy event log data.
  64       *
  65       * @return array|null
  66       */
  67      protected function get_legacy_logdata() {
  68          return $this->legacylogdata;
  69      }
  70  
  71      /**
  72       * Return localised event name.
  73       *
  74       * @return string
  75       */
  76      public static function get_name() {
  77          return get_string('eventwebserviceloginfailed', 'webservice');
  78      }
  79  
  80      /**
  81       * Init method.
  82       *
  83       * @return void
  84       */
  85      protected function init() {
  86          $this->data['crud'] = 'r';
  87          $this->data['edulevel'] = self::LEVEL_OTHER;
  88          $this->context = \context_system::instance();
  89      }
  90  
  91      /**
  92       * Set the legacy event log data.
  93       *
  94       * @param array $logdata The log data.
  95       * @return void
  96       */
  97      public function set_legacy_logdata($logdata) {
  98          $this->legacylogdata = $logdata;
  99      }
 100  
 101      /**
 102       * Custom validation.
 103       *
 104       * It is recommended to set the properties:
 105       * - $other['tokenid']
 106       * - $other['username']
 107       *
 108       * However they are not mandatory as they are not always known.
 109       *
 110       * Please note that the token CANNOT be specified, it is considered
 111       * as a password and should never be displayed.
 112       *
 113       * @throws \coding_exception
 114       * @return void
 115       */
 116      protected function validate_data() {
 117          parent::validate_data();
 118          if (!isset($this->other['reason'])) {
 119             throw new \coding_exception('The \'reason\' value must be set in other.');
 120          } else if (!isset($this->other['method'])) {
 121             throw new \coding_exception('The \'method\' value must be set in other.');
 122          } else if (isset($this->other['token'])) {
 123             throw new \coding_exception('The \'token\' value must not be set in other.');
 124          }
 125      }
 126  
 127      public static function get_other_mapping() {
 128          return false;
 129      }
 130  }