Skip to content

Commit

Permalink
feat: Introduce gated functionality for use in Totara (17.3+) without…
Browse files Browse the repository at this point in the history
… patches.
  • Loading branch information
LiamKearn committed Feb 26, 2023
1 parent c511822 commit 941aab6
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
59 changes: 59 additions & 0 deletions classes/watcher/login_watcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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/>.

namespace tool_mfa\watcher;

defined('MOODLE_INTERNAL') || die();

use core\hook\after_require_login as after_require_login_hook;
use core\hook\after_config as after_config_hook;

if (class_exists('\totara_core\hook\base')) {
require_once($CFG->dirroot . '/admin/tool/mfa/lib.php');

/**
* Watches Totara hooks to ensure a user is authenticated.
*
* Forwards on the events until:
* `TODO - PLATFORM-117 to create a watcher to enable those functions via this hook`
*
* @package tool_mfa
* @author Liam Kearney <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class login_watcher {
/**
* Forwards calls to tool_mfa_after_require_login.
*/
public static function ensure_authenticated(after_require_login_hook $hook) {
tool_mfa_after_require_login(
$hook->courseorid,
$hook->autologinguest,
$hook->cm,
$hook->setwantsurltome,
$hook->preventredirect
);
}

/**
* Forwards calls to tool_mfa_after_config.
*/
public static function check_authenticated(after_config_hook $hook) {
tool_mfa_after_config();
}
}
}
45 changes: 45 additions & 0 deletions db/hooks.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?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/>.

/**
* Definition of MFA sub-plugins (factors).
*
* @package tool_mfa
* @author Liam Kearney <[email protected]>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

// Hooks are Totara specific.
if (class_exists('\totara_core\hook\base')) {
$watchers = [
[
'hookname' => '\core\hook\after_require_login',
'callback' => '\tool_mfa\watcher\login_watcher::ensure_authenticated',
'includefile' => null,
'priority' => 100,
],
[
'hookname' => '\core\hook\after_config',
'callback' => '\tool_mfa\watcher\login_watcher::check_authenticated',
'includefile' => null,
'priority' => 100,
],
];
}

0 comments on commit 941aab6

Please sign in to comment.