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 |
* Amanote observer definitions.
|
|
|
19 |
*
|
|
|
20 |
* @package filter_amanote
|
|
|
21 |
* @copyright 2024 Amaplex Software
|
|
|
22 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
23 |
*/
|
|
|
24 |
|
|
|
25 |
defined('MOODLE_INTERNAL') || die();
|
|
|
26 |
|
|
|
27 |
require_once($CFG->libdir . '/filelib.php');
|
|
|
28 |
|
|
|
29 |
/**
|
|
|
30 |
* Amanote observer functions.
|
|
|
31 |
*
|
|
|
32 |
* @copyright 2024 Amaplex Software
|
|
|
33 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
34 |
*/
|
|
|
35 |
class filter_amanote_observer {
|
|
|
36 |
/**
|
|
|
37 |
* Global signout the user on Amanote when the user logs out of Moodle.
|
|
|
38 |
*
|
|
|
39 |
* @param \core\event\user_loggedout $event The event object.
|
|
|
40 |
*/
|
|
|
41 |
public static function user_loggedout(\core\event\user_loggedout $event) {
|
|
|
42 |
global $DB, $CFG;
|
|
|
43 |
|
|
|
44 |
try {
|
|
|
45 |
// Get the Moodle mobile service.
|
|
|
46 |
$serviceparams = ['shortname' => MOODLE_OFFICIAL_MOBILE_SERVICE, 'enabled' => 1];
|
|
|
47 |
$service = $DB->get_record('external_services', $serviceparams);
|
|
|
48 |
|
|
|
49 |
// Get the user's token.
|
|
|
50 |
$context = \context_system::instance();
|
|
|
51 |
$token = $DB->get_record(
|
|
|
52 |
'external_tokens',
|
|
|
53 |
[
|
|
|
54 |
'userid' => $event->userid,
|
|
|
55 |
'externalserviceid' => $service->id,
|
|
|
56 |
'contextid' => $context->id,
|
|
|
57 |
]
|
|
|
58 |
);
|
|
|
59 |
|
|
|
60 |
if (!$token) {
|
|
|
61 |
return;
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
// Sign out the user from Amanote.
|
|
|
65 |
$siteid = preg_replace('(^https?://)', '', $CFG->wwwroot, 1);
|
|
|
66 |
|
|
|
67 |
$url = 'https://api.amanote.com/oidc/global-signout?' .
|
|
|
68 |
'provider=moodle&' .
|
|
|
69 |
'siteId=' . $siteid . '&' .
|
|
|
70 |
'token=' . $token->token . '&' .
|
|
|
71 |
'userId=' . $event->userid;
|
|
|
72 |
|
|
|
73 |
$curl = new \curl();
|
|
|
74 |
$curl->setHeader('Content-Type: application/json');
|
|
|
75 |
$curl->get($url);
|
|
|
76 |
|
|
|
77 |
} catch (\Exception $e) {
|
|
|
78 |
debugging('An error occurred: ' . $e->getMessage() . $e->getTraceAsString(), DEBUG_DEVELOPER);
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
}
|