From 0a976df90c79a997fa9d259d0945f43386d17d20 Mon Sep 17 00:00:00 2001 From: Marina Glancy Date: Tue, 3 Feb 2015 10:37:42 +0800 Subject: [PATCH] MDL-49003 login: prevent signup when user is logged in --- lang/en/error.php | 1 + login/signup.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lang/en/error.php b/lang/en/error.php index ac044adc33f..591c128d55e 100644 --- a/lang/en/error.php +++ b/lang/en/error.php @@ -145,6 +145,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'; diff --git a/login/signup.php b/login/signup.php index 990a9e94b80..54002b7745c 100644 --- a/login/signup.php +++ b/login/signup.php @@ -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()) {