Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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 localised event name.
64
     *
65
     * @return string
66
     */
67
    public static function get_name() {
68
        return get_string('eventwebserviceloginfailed', 'webservice');
69
    }
70
 
71
    /**
72
     * Init method.
73
     *
74
     * @return void
75
     */
76
    protected function init() {
77
        $this->data['crud'] = 'r';
78
        $this->data['edulevel'] = self::LEVEL_OTHER;
79
        $this->context = \context_system::instance();
80
    }
81
 
82
    /**
83
     * Custom validation.
84
     *
85
     * It is recommended to set the properties:
86
     * - $other['tokenid']
87
     * - $other['username']
88
     *
89
     * However they are not mandatory as they are not always known.
90
     *
91
     * Please note that the token CANNOT be specified, it is considered
92
     * as a password and should never be displayed.
93
     *
94
     * @throws \coding_exception
95
     * @return void
96
     */
97
    protected function validate_data() {
98
        parent::validate_data();
99
        if (!isset($this->other['reason'])) {
100
           throw new \coding_exception('The \'reason\' value must be set in other.');
101
        } else if (!isset($this->other['method'])) {
102
           throw new \coding_exception('The \'method\' value must be set in other.');
103
        } else if (isset($this->other['token'])) {
104
           throw new \coding_exception('The \'token\' value must not be set in other.');
105
        }
106
    }
107
 
108
    public static function get_other_mapping() {
109
        return false;
110
    }
111
}