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 |
namespace tool_mfa;
|
|
|
18 |
|
|
|
19 |
defined('MOODLE_INTERNAL') || die();
|
|
|
20 |
|
|
|
21 |
global $CFG;
|
|
|
22 |
require_once($CFG->libdir.'/adminlib.php');
|
|
|
23 |
require_once(__DIR__ . '/../lib.php');
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Trait for testing this plugin
|
|
|
27 |
*
|
|
|
28 |
* @package tool_mfa
|
|
|
29 |
* @author Mikhail Golenkov <golenkovm@gmail.com>
|
|
|
30 |
* @author Peter Burnett <peterburnett@catalyst-au.net>
|
|
|
31 |
* @copyright Catalyst IT
|
|
|
32 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
33 |
*/
|
|
|
34 |
trait tool_mfa_trait {
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
* Sets the state of the factor, in particular the weight and whether it is enabled
|
|
|
38 |
*
|
|
|
39 |
* @param string $factorname
|
|
|
40 |
* @param int $enabled
|
|
|
41 |
* @param int $weight
|
|
|
42 |
*/
|
|
|
43 |
public function set_factor_state($factorname, $enabled = 0, $weight = 100) {
|
|
|
44 |
$factor = \tool_mfa\plugininfo\factor::get_factor($factorname);
|
|
|
45 |
$this->set_factor_config($factor, 'enabled', $enabled);
|
|
|
46 |
$this->set_factor_config($factor, 'weight', $weight);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Sets config variable for given factor.
|
|
|
51 |
*
|
|
|
52 |
* @param object $factor object of the factor class
|
|
|
53 |
* @param string $key
|
|
|
54 |
* @param mixed $value
|
|
|
55 |
*/
|
|
|
56 |
public function set_factor_config($factor, $key, $value) {
|
|
|
57 |
\tool_mfa\manager::set_factor_config([$key => $value], 'factor_' . $factor->name);
|
|
|
58 |
|
|
|
59 |
if ($key == 'enabled') {
|
|
|
60 |
if ($value == 1) {
|
|
|
61 |
\tool_mfa\manager::do_factor_action($factor->name, 'enable');
|
|
|
62 |
} else {
|
|
|
63 |
\tool_mfa\manager::do_factor_action($factor->name, 'disable');
|
|
|
64 |
}
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
}
|