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
defined('MOODLE_INTERNAL') || die();
18
 
19
global $CFG;
20
require_once(__DIR__ . '/../../lib.php');
21
 
22
/**
23
 * Data generator for tool_mfa plugin.
24
 *
25
 * @package    tool_mfa
26
 * @category   test
27
 * @copyright  2024 David Woloszyn <david.woloszyn@moodle.com>
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 */
30
class tool_mfa_generator extends component_generator_base {
31
    /**
32
     * Create user factors.
33
     *
34
     * @param   array $record
35
     * @return  stdClass
36
     */
37
    public function create_user_factors(array $record): \stdClass {
38
        global $DB;
39
 
40
        $factorobject = \tool_mfa\plugininfo\factor::get_factor($record['factor']);
41
        if (!$factorobject) {
42
            throw new coding_exception('Unknown factor supplied.');
43
        }
44
 
45
        $user = $DB->get_record('user', ['username' => $record['username']]);
46
        if (!$user) {
47
            throw new coding_exception('No user found with that username.');
48
        }
49
 
50
        $record = (object) array_merge([
51
            'userid' => $user->id,
52
            'secret' => '555553',
53
            'timecreated' => time() - DAYSECS,
54
            'createdfromip' => '0:0:0:0:0:0:0:1',
55
            'timemodified' => time() - MINSECS,
56
            'lastverified' => time(),
57
            'revoked' => 0,
58
            'lockcounter' => 0,
59
        ], $record);
60
        $record->id = $DB->insert_record('tool_mfa', $record);
61
 
62
        return $record;
63
    }
64
}