This repository was archived by the owner on Jun 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlib.php
More file actions
104 lines (92 loc) · 4.07 KB
/
Copy pathlib.php
File metadata and controls
104 lines (92 loc) · 4.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* @package local_twofactorauth
* @copyright infinitail
* @license http://www.gnu.org/copyleft/gpl.html gnu gpl v3 or later
*/
require_once __DIR__.'/locallib.php';
// Avoid problem after installation...
if (!is_file(__DIR__.'/vendor/autoload.php')) {
print_error('runcomposer', 'local_twofactorauth');
}
/**
* My profile page customization
* Add user 2FA setting links
*/
function local_twofactorauth_myprofile_navigation(\core_user\output\myprofile\tree $tree, $user, $iscurrentuser) {
global $DB, $USER;
// Display not allowed if non admin user want to see other user.
if (!is_siteadmin($USER) && !$iscurrentuser) {
return;
}
$pluginsettings = get_config('local_twofactorauth');
if ($pluginsettings->enable_twofactorauth &&
(is_siteadmin($user) || (!is_siteadmin($user) && $pluginsettings->allow_non_admin))) {
$category = new core_user\output\myprofile\category(
'local_twofactorauth',
get_string('myprofilecategoryname', 'local_twofactorauth')
);
$tree->add_category($category);
// Display user's status and configuration links.
$providers = local\twofactorauth\locallib::get_providers();
foreach ($providers as $id=>$provider) {
if ($pluginsettings->{"allow_{$provider}"}) {
$record = $DB->get_record('local_2fa_users', ['userid'=>$user->id, 'providerid'=>$id]);
$status = (!empty($record) && !empty($record->verified))
? '<span class="badge badge-success">' . get_string('enabled', 'local_twofactorauth') . '</span>'
: '<span class="badge badge-secondary">' . get_string('disabled', 'local_twofactorauth') . '</span>';
$node = new core_user\output\myprofile\node(
'local_twofactorauth',
"{$provider}_node",
get_string($provider, 'local_twofactorauth'),
null,
new moodle_url('/local/twofactorauth/provider.php', ['uid'=>$user->id, 'provider'=>$provider]),
get_string('status') . ': ' . $status
);
$tree->add_node($node);
}
}
/* TODO: Add trusted device function
// Trust device and avoid two factor authenticaton
$node = new core_user\output\myprofile\node(
'local_twofactorauth',
'trustdevice',
get_string('trustdevice', 'local_twofactorauth'),
null,
new moodle_url('/local/twofactorauth/trustdevice.php', ['uid'=>$user->id]),
get_string('status')
);
$tree->add_node($node);
*/
}
}
/**
* Check two factor auth status and display form
* (HACK navigation menu display function)
*/
function local_twofactorauth_extend_navigation(\global_navigation $nav) {
global $CFG, $USER, $PAGE;
//return; // DEBUG
if (local\twofactorauth\locallib::is_2fa_required() === true) {
// Skip if in provider selector page for avoid infinite loop
$url = parse_url(new moodle_url('/local/twofactorauth/selector.php'));
if ($_SERVER['REQUEST_URI'] !== $url['path']) {
// Display 2FA provider selector
redirect(new moodle_url('/local/twofactorauth/selector.php'));
}
}
}