Login callbacks: Difference between revisions
Line 251: | Line 251: | ||
WIP: Fire any additional actions required after a user creates an account. This function is passed the submitted form data. | WIP: Fire any additional actions required after a user creates an account. This function is passed the submitted form data. | ||
<code> | <code> |
Revision as of 04:29, 15 October 2019
There are cases where we want any plugin to do some check or action as part of the require_login check or related things around logging in or passwords but which are not handled by an authentication plugin.
after_require_login
Moodle 3.7
This callback allow a plugin to add additional behavior after require_login is called. Some use cases:
- replacing the sitepolicy feature with a more robust / advanced version
- augmenting the 'user fully setup' workflow to add more steps but outside their profile editing page
- adding extra layers of checks, eg an ip address check but doing this across whole courses instead of at the sitelevel which is too coarse, or at the activity level which is too fine.
- enforcing various types of course visibility dependencies, eg 'before you can do course X you need to complete course Y'
function tool_myplugin_after_require_login() {
if (should_divert()) {
redirect($somewhere);
}
}
Implemented in https://tracker.moodle.org/browse/MDL-60470
check_password_policy
Moodle 3.6
This callback allows a plugin to add additional password tests.
https://tracker.moodle.org/browse/MDL-61694
print_password_policy
Moodle 3.8
This callback allows a plugin to explain the additional password added via check_password_policy
https://tracker.moodle.org/browse/MDL-66278
pre_signup_requests
Moodle 3.5
eg to do actions before sign up such as acceptance of policies, validations, etc
function tool_myplugin_pre_signup_requests() {
// Do some special policy
}
https://tracker.moodle.org/browse/MDL-61485
extend_change_password_form
Moodle 3.8
WIP: This callback allows for injection of additional form elements into the change password form, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_extend_change_password_form($mform, $user) {
// Inject a static element of the user's username
$mform->addElement('static', 'injectedstatic', $user->username);
}
https://tracker.moodle.org/browse/MDL-66173
extend_set_password_form
Moodle 3.8
WIP: This callback allows for injection of additional form elements into the set password form, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_extend_set_password_form($mform, $user) {
// Inject a static element of the user's username
$mform->addElement('static', 'injectedstatic', $user->username);
}
https://tracker.moodle.org/browse/MDL-66173
extend_forgot_password_form
Moodle 3.8
WIP: This callback allows for injection of additional form elements into the forgot password form, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_extend_forgot_password_form($mform) {
// Inject a static element of the word 'injected'
$mform->addElement('static', 'injectedstatic', 'injected');
}
https://tracker.moodle.org/browse/MDL-66173
extend_signup_form
Moodle 3.8
WIP: This callback allows for injection of additional form elements into the forgot password form, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_extend_signup_form($mform) {
// Inject a static element of the word 'injected'
$mform->addElement('static', 'injectedstatic', 'injected');
}
https://tracker.moodle.org/browse/MDL-66173
validate_extend_change_password_form
Moodle 3.8
WIP: This callback allows for additional validation of existing and additional form elements, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_validate_extend_change_password_form($data, $user) {
// Validate that an injected elements equals the word 'test'
$errors = array();
if ($data['injectedtext'] != 'test') {
$errors['injectedtext'] = 'wrong';
}
return $errors;
}
https://tracker.moodle.org/browse/MDL-66173
validate_extend_set_password_form
Moodle 3.8
WIP: This callback allows for additional validation of existing and additional form elements, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_validate_extend_set_password_form($data, $user) {
// Validate that an injected elements equals the word 'test'
$errors = array();
if ($data['injectedtext'] != 'test') {
$errors['injectedtext'] = 'wrong';
}
return $errors;
}
https://tracker.moodle.org/browse/MDL-66173
validate_extend_forgot_password_form
Moodle 3.8
WIP: This callback allows for additional validation of existing and additional form elements, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_validate_extend_forgot_password_form($data) {
// Validate that an injected elements equals the word 'test'
$errors = array();
if ($data['injectedtext'] != 'test') {
$errors['injectedtext'] = 'wrong';
}
return $errors;
}
https://tracker.moodle.org/browse/MDL-66173
validate_extend_signup_form
Moodle 3.8
WIP: This callback allows for additional validation of existing and additional form elements, to allow for more complicated behaviour such as 2FA.
Note: This hook is not supported or compatible with the Webservices API or the Moodle mobile app. It does not damage or interrupt any current functionality of the mobile application, however injected form elements and actions will not be executed for mobile users.
function tool_myplugin_validate_extend_signup_form($data) {
// Validate that an injected elements equals the word 'test'
$errors = array();
if ($data['injectedtext'] != 'test') {
$errors['injectedtext'] = 'wrong';
}
return $errors;
}
https://tracker.moodle.org/browse/MDL-66173
post_change_password_requests
Moodle 3.8
WIP: Fire any additional actions required after a user changes their password. This function is passed the submitted form data.
function tool_myplugin_post_change_password_requests($data) {
// Display a popup message that echoes what a user submitted in an injected element
$message = ('post_change_password_request - Input: '.$data->injectedtext);
echo "<script type='text/javascript'>alert('$message');</script>";
}
https://tracker.moodle.org/browse/MDL-66173
post_set_password_requests
Moodle 3.8
WIP: Fire any additional actions required after a user resets their password. This function is passed the submitted form data.
function tool_myplugin_post_set_password_requests($data) {
// Display a popup message that echoes what a user submitted in an injected element
$message = ('post_set_password_request - Input: '.$data->injectedtext);
echo "<script type='text/javascript'>alert('$message');</script>";
}
https://tracker.moodle.org/browse/MDL-66173
post_forgot_password_requests
Moodle 3.8
WIP: Fire any additional actions required after a user submits a password reset request. This function is passed the submitted form data.
function tool_myplugin_post_forgot_password_requests($data) {
// Display a popup message that echoes what a user submitted in an injected element
$message = ('post_forgot_password_request - Input: '.$data->injectedtext);
echo "<script type='text/javascript'>alert('$message');</script>";
}
https://tracker.moodle.org/browse/MDL-66173
post_signup_requests
Moodle 3.8
WIP: Fire any additional actions required after a user creates an account. This function is passed the submitted form data.
function tool_myplugin_post_signup_requests($data) {
// Display a popup message that echoes what a user submitted in an injected element
$message = ('post_signup_request - Input: '.$data->injectedtext);
echo "<script type='text/javascript'>alert('$message');</script>";
}