1
0
mirror of https://github.com/moodle/moodle.git synced 2025-04-24 18:04:43 +02:00

MDL-57102 auth: Add new signup_is_enabled function

And apply the function in:
- login/signup.php
- blocks/login/block_login.php
This commit is contained in:
Juan Leyva 2016-11-23 19:32:48 +00:00
parent cd4a6b8b0b
commit 813320fbb6
4 changed files with 25 additions and 11 deletions

@ -9,6 +9,7 @@ information provided here is intended especially for developers.
* The authentication plugin auth_radius has been moved to https://github.com/moodlehq/moodle-auth_radius
* New auth_email::user_signup_with_confirmation() method has a new optional parameter $confirmationurl to provide a different
confirmation URL.
* New signup_is_enabled() function available in lib/authlib.php to safely check if sign-up is enabled in the site.
=== 3.0 ===

@ -33,6 +33,8 @@ class block_login extends block_base {
function get_content () {
global $USER, $CFG, $SESSION, $OUTPUT;
require_once($CFG->libdir . '/authlib.php');
$wwwroot = '';
$signup = '';
@ -48,11 +50,8 @@ class block_login extends block_base {
$wwwroot = str_replace("http://", "https://", $CFG->wwwroot);
}
if (!empty($CFG->registerauth)) {
$authplugin = get_auth_plugin($CFG->registerauth);
if ($authplugin->can_signup()) {
$signup = $wwwroot . '/login/signup.php';
}
if (signup_is_enabled()) {
$signup = $wwwroot . '/login/signup.php';
}
// TODO: now that we have multiauth it is hard to find out if there is a way to change password
$forgot = $wwwroot . '/login/forgot_password.php';

@ -916,3 +916,21 @@ function signup_get_user_confirmation_authplugin() {
}
return $authplugin;
}
/**
* Check if sign-up is enabled in the site. If is enabled, the function will return the authplugin instance.
*
* @return mixed false if sign-up is not enabled, the authplugin instance otherwise.
* @since Moodle 3.2
*/
function signup_is_enabled() {
global $CFG;
if (!empty($CFG->registerauth)) {
$authplugin = get_auth_plugin($CFG->registerauth);
if ($authplugin->can_signup()) {
return $authplugin;
}
}
return false;
}

@ -26,6 +26,7 @@
require('../config.php');
require_once($CFG->dirroot . '/user/editlib.php');
require_once($CFG->libdir . '/authlib.php');
// Try to prevent searching for sites that allow sign-up.
if (!isset($CFG->additionalhtmlhead)) {
@ -33,12 +34,7 @@ if (!isset($CFG->additionalhtmlhead)) {
}
$CFG->additionalhtmlhead .= '<meta name="robots" content="noindex" />';
if (empty($CFG->registerauth)) {
print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
}
$authplugin = get_auth_plugin($CFG->registerauth);
if (!$authplugin->can_signup()) {
if (!$authplugin = signup_is_enabled()) {
print_error('notlocalisederrormessage', 'error', '', 'Sorry, you may not use this page.');
}