diff --git a/lang/en/error.php b/lang/en/error.php index 1acf56bc9a91f..8588576e4fd65 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -144,6 +144,7 @@ $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'; diff --git a/login/signup.php b/login/signup.php index 976b3420f8784..66e622c1bf4a9 100644 --- a/login/signup.php +++ b/login/signup.php @@ -48,6 +48,22 @@ $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()) {