From 033f742e4aa17da5acee6b17ea5e5ab924bc9eb4 Mon Sep 17 00:00:00 2001 From: meirzamoodle Date: Fri, 4 Aug 2023 04:30:21 +0700 Subject: [PATCH] MDL-78685 auth_oauth2: Added logged-in status check --- auth/oauth2/confirm-linkedlogin.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/auth/oauth2/confirm-linkedlogin.php b/auth/oauth2/confirm-linkedlogin.php index 879655ae92b..cf031be5ba2 100644 --- a/auth/oauth2/confirm-linkedlogin.php +++ b/auth/oauth2/confirm-linkedlogin.php @@ -48,11 +48,7 @@ if ($confirmed) { throw new \moodle_exception('cannotfinduser', '', '', $userid); } - if (!$user->suspended) { - complete_user_login($user); - - \core\session\manager::apply_concurrent_login_limit($user->id, session_id()); - + if ($user->id == $USER->id) { // Check where to go, $redirect has a higher preference. if (empty($redirect) and !empty($SESSION->wantsurl) ) { $redirect = $SESSION->wantsurl; @@ -69,14 +65,24 @@ if ($confirmed) { $PAGE->set_heading($COURSE->fullname); echo $OUTPUT->header(); echo $OUTPUT->box_start('generalbox centerpara boxwidthnormal boxaligncenter'); - echo "

".get_string("thanks").", ". fullname($USER) . "

\n"; + echo "

".get_string("thanks").", ". fullname($user) . "

\n"; echo "

".get_string("confirmed")."

\n"; - echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses')); + // If $wantsurl and $redirect are empty, then the button will navigate the identical user to the dashboard. + if ($user->id == $USER->id) { + echo $OUTPUT->single_button("$CFG->wwwroot/course/", get_string('courses')); + } else if (!isloggedin() || isguestuser()) { + echo $OUTPUT->single_button(get_login_url(), get_string('login')); + } else { + echo $OUTPUT->single_button("$CFG->wwwroot/login/logout.php", get_string('logout')); + } echo $OUTPUT->box_end(); echo $OUTPUT->footer(); exit; } else { - \core\notification::error(get_string('confirmationinvalid', 'auth_oauth2')); + // Avoid error if logged-in user visiting the page. + if (!isloggedin()) { + \core\notification::error(get_string('confirmationinvalid', 'auth_oauth2')); + } } redirect("$CFG->wwwroot/");