MDL-49003 login: prevent signup when user is logged in

This commit is contained in:
Marina Glancy 2015-02-03 10:37:42 +08:00 committed by Eloy Lafuente (stronk7)
parent 78c36b065f
commit 6a2c10a89d
2 changed files with 17 additions and 0 deletions

View File

@ -144,6 +144,7 @@ $string['cannotsetupblock'] = 'Blocks tables could NOT be set up successfully!';
$string['cannotsetupcapformod'] = 'Could not set up the capabilities for {$a}';
$string['cannotsetupcapforplugin'] = 'Could not set up the capabilities for {$a}';
$string['cannotshowhidecoursesincategory'] = 'Cannot show/hide the courses in category {$a}.';
$string['cannotsignup'] = 'You cannot create a new account because you are already logged in as {$a}.';
$string['cannotunassigncap'] = 'Could not unassign deprecated capability {$a->cap} from role {$a->role}';
$string['cannotunassignrolefrom'] = 'Cannot unassign this user from role id: {$a}';
$string['cannotunzipfile'] = 'Cannot unzip file';

View File

@ -48,6 +48,22 @@ $PAGE->https_required();
$PAGE->set_url('/login/signup.php');
$PAGE->set_context(context_system::instance());
// Override wanted URL, we do not want to end up here again if user clicks "Login".
$SESSION->wantsurl = $CFG->wwwroot . '/';
if (isloggedin() and !isguestuser()) {
// Prevent signing up when already logged in.
echo $OUTPUT->header();
echo $OUTPUT->box_start();
$logout = new single_button(new moodle_url($CFG->httpswwwroot . '/login/logout.php',
array('sesskey' => sesskey(), 'loginpage' => 1)), get_string('logout'), 'post');
$continue = new single_button(new moodle_url('/'), get_string('cancel'), 'get');
echo $OUTPUT->confirm(get_string('cannotsignup', 'error', fullname($USER)), $logout, $continue);
echo $OUTPUT->box_end();
echo $OUTPUT->footer();
exit;
}
$mform_signup = $authplugin->signup_form();
if ($mform_signup->is_cancelled()) {