diff --git a/classes/watcher/login_watcher.php b/classes/watcher/login_watcher.php new file mode 100644 index 00000000..890fd134 --- /dev/null +++ b/classes/watcher/login_watcher.php @@ -0,0 +1,67 @@ +. + +namespace tool_mfa\watcher; + +defined('MOODLE_INTERNAL') || die(); + +use core\hook\after_require_login; +use core\hook\after_config; +use totara_core\hook\base; + +// Hooks are Totara specific. +if (!class_exists(base::class)) { + return; +} + +require_once($CFG->dirroot . '/admin/tool/mfa/lib.php'); + +/** + * Watches Totara hooks to ensure a user is authenticated. + * + * Forwards on the events until Totara implements: + * `TODO - PLATFORM-117 to create a watcher to enable those functions via this hook` + * + * @package tool_mfa + * @author Liam Kearney + * @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. + * + * @param after_require_login $hook + */ + public static function ensure_authenticated(after_require_login $hook) { + tool_mfa_after_require_login( + $hook->courseorid, + $hook->autologinguest, + $hook->cm, + $hook->setwantsurltome, + $hook->preventredirect + ); + } + + /** + * Forwards calls to tool_mfa_after_config. + * + * @param after_config $hook + */ + public static function check_authenticated(after_config $hook) { + tool_mfa_after_config(); + } +} diff --git a/db/hooks.php b/db/hooks.php new file mode 100644 index 00000000..915386f8 --- /dev/null +++ b/db/hooks.php @@ -0,0 +1,52 @@ +. + +/** + * Definition of MFA sub-plugins (factors). + * + * @package tool_mfa + * @author Liam Kearney + * @copyright Catalyst IT + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +use core\hook\after_require_login; +use core\hook\after_config; +use tool_mfa\watcher\login_watcher; +use totara_core\hook\base; + +// Hooks are Totara specific. +if (!class_exists(base::class)) { + return; +} + +$watchers = [ + [ + 'hookname' => after_require_login::class, + 'callback' => [login_watcher::classs, 'ensure_authenticated'], + 'includefile' => null, + 'priority' => 100, + ], + [ + 'hookname' => after_config::class, + 'callback' => [login_watcher::class, 'check_authenticated'], + 'includefile' => null, + 'priority' => 100, + ], +]; +