Skip to content

Commit

Permalink
MDL-49003 login: prevent signup when user is logged in
Browse files Browse the repository at this point in the history
  • Loading branch information
marinaglancy authored and stronk7 committed Feb 10, 2015
1 parent e314024 commit 7a6581f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en/error.php
Expand Up @@ -145,6 +145,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';
Expand Down
16 changes: 16 additions & 0 deletions login/signup.php
Expand Up @@ -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()) {
Expand Down

0 comments on commit 7a6581f

Please sign in to comment.