Files
meetletacbfree/ajax/registration.php
T

84 lines
2.4 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
/**
* Ajax endpoint: activate / recheck / deactivate MeetLet site registration.
*
* @package mod_meetletacbfree
* @copyright 2026 MeetLet
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define('AJAX_SCRIPT', true);
require_once('../../../config.php');
use mod_meetletacbfree\registration\error_mapper;
use mod_meetletacbfree\registration\manager;
use mod_meetletacbfree\registration\registration_exception;
require_login();
require_capability('moodle/site:config', context_system::instance());
require_sesskey();
$action = required_param('action', PARAM_ALPHA);
$apiurl = optional_param('registration_api_url', '', PARAM_URL);
header('Content-Type: application/json; charset=utf-8');
try {
if ($apiurl !== '') {
set_config(manager::CONFIG_API_URL, rtrim($apiurl, '/'), 'meetletacbfree');
}
if ($action === 'activate') {
manager::activate();
echo json_encode([
'success' => true,
'message' => get_string('registration_activated', 'meetletacbfree'),
'summary' => manager::status_summary(),
]);
exit;
}
if ($action === 'recheck' || $action === 'refresh' || $action === 'validate') {
manager::recheck(true);
echo json_encode([
'success' => true,
'message' => get_string('registration_rechecked', 'meetletacbfree'),
'summary' => manager::status_summary(),
]);
exit;
}
if ($action === 'deactivate') {
manager::deactivate();
echo json_encode([
'success' => true,
'message' => get_string('registration_deactivated', 'meetletacbfree'),
'summary' => manager::status_summary(),
]);
exit;
}
if ($action === 'status') {
echo json_encode([
'success' => true,
'summary' => manager::status_summary(),
]);
exit;
}
throw new moodle_exception('invalidparameter');
} catch (Throwable $e) {
$ex = registration_exception::from_throwable($e);
$mapped = error_mapper::from_exception($ex);
echo json_encode([
'success' => false,
'error' => $mapped['message'] ?? $ex->get_api_message(),
'error_code' => $ex->get_error_code(),
'request_id' => $ex->get_request_id(),
'summary' => manager::status_summary(),
]);
}