diff --git a/README.md b/README.md index 9420c6d2..4acd9df6 100644 --- a/README.md +++ b/README.md @@ -64,7 +64,8 @@ A minimum of PHP7.0 is required to run this plugin. | Moodle 3.8 -3.9 | master | None | | Moodle 3.7 | master | MDL-66340 | | Moodle 3.5-3.6 | master | MDL-66340, MDL-60470 | -| Totara 12-15 | master | MDL-66340, MDL-60470 | +| Totara 12-17 | master | MDL-66340, MDL-60470 | +| Totara 17.3+ | master | None | ## Installation 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..4e87a18f --- /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::class, 'ensure_authenticated'], + 'includefile' => null, + 'priority' => 100, + ], + [ + 'hookname' => after_config::class, + 'callback' => [login_watcher::class, 'check_authenticated'], + 'includefile' => null, + 'priority' => 100, + ], +]; +