Skip to content

Commit e34e1a5

Browse files
committed
Plugin: Azure: Fix session redirect after login from custom page - refs BT#22335
1 parent f67d2a3 commit e34e1a5

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

main/inc/lib/api.lib.php

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,7 +1449,7 @@ function api_protect_teacher_script()
14491449
function api_block_anonymous_users($printHeaders = true)
14501450
{
14511451
$user = api_get_user_info();
1452-
if (!(isset($user['user_id']) && $user['user_id']) || api_is_anonymous($user['user_id'], true)) {
1452+
if (empty($user['user_id']) || api_is_anonymous($user['user_id'], true)) {
14531453
api_not_allowed($printHeaders);
14541454

14551455
return false;
@@ -4030,26 +4030,9 @@ function api_not_allowed(
40304030

40314031
global $this_section;
40324032

4033-
// Check if a custom file (login.tpl) exists for custompages included overrides
4034-
if ((!isset($user_id) || api_is_anonymous()) && CustomPages::enabled()) {
4035-
$customLoginTemplate = Template::findTemplateFilePath('custompage/login.tpl');
4036-
if (file_exists(api_get_path(SYS_TEMPLATE_PATH).$customLoginTemplate)) {
4037-
if (empty($_SESSION['request_uri'])) {
4038-
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
4039-
}
4040-
$tpl = new Template(null, false, false);
4041-
$content = $tpl->fetch($customLoginTemplate);
4042-
$tpl->assign('content', $content);
4043-
$tpl->display_no_layout_template();
4044-
exit;
4045-
}
4046-
}
4047-
4048-
if (CustomPages::enabled() && !isset($user_id)) {
4049-
if (empty($user_id)) {
4050-
// Why the CustomPages::enabled() need to be to set the request_uri
4051-
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
4052-
}
4033+
if (CustomPages::enabled() && (empty($user_id) || api_is_anonymous())) {
4034+
// Why the CustomPages::enabled() need to be to set the request_uri
4035+
$_SESSION['request_uri'] = $_SERVER['REQUEST_URI'];
40534036
CustomPages::display(CustomPages::INDEX_UNLOGGED);
40544037
}
40554038

main/inc/lib/redirect.class.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ public static function go($url = '')
5353
*/
5454
public static function session_request_uri($logging_in = false, $user_id = null)
5555
{
56-
$no_redirection = isset($_SESSION['noredirection']) ? $_SESSION['noredirection'] : false;
56+
$no_redirection = $_SESSION['noredirection'] ?? false;
57+
$no_redirection = $GLOBALS['noredirection'] ?? $no_redirection;
5758

5859
if ($no_redirection) {
5960
unset($_SESSION['noredirection']);
61+
unset($GLOBALS['noredirection']);
6062

6163
return;
6264
}
6365

6466
$url = isset($_SESSION['request_uri']) ? Security::remove_XSS($_SESSION['request_uri']) : '';
65-
unset($_SESSION['request_uri']);
6667

6768
$afterLogin = Session::read('redirect_after_not_allow_page');
6869

@@ -71,11 +72,11 @@ public static function session_request_uri($logging_in = false, $user_id = null)
7172
self::navigate($afterLogin);
7273
}
7374
if (!empty($url)) {
75+
$_SESSION['custom_request_uri'] = $_SERVER['REQUEST_URI'];
76+
unset($_SESSION['request_uri']);
7477
self::navigate($url);
75-
} elseif ($logging_in ||
76-
(isset($_REQUEST['sso_referer']) && !empty($_REQUEST['sso_referer']))
77-
) {
78-
if (isset($user_id)) {
78+
} elseif ($logging_in || !empty($_REQUEST['sso_referer'])) {
79+
if (!empty($user_id)) {
7980
$allow = api_get_configuration_value('plugin_redirection_enabled');
8081
if ($allow) {
8182
$allow = api_get_configuration_value('plugin_redirection_enabled');
@@ -121,8 +122,8 @@ public static function session_request_uri($logging_in = false, $user_id = null)
121122
if (api_is_multiple_url_enabled()) {
122123
// if multiple URLs are enabled, make sure he's admin of the
123124
// current URL before redirecting
124-
$url = api_get_current_access_url_id();
125-
if (api_is_platform_admin_by_id($user_id, $url)) {
125+
$urlId = api_get_current_access_url_id();
126+
if (api_is_platform_admin_by_id($user_id, $urlId)) {
126127
self::navigate(api_get_path(WEB_CODE_PATH).'admin/index.php');
127128
}
128129
} else {

plugin/azure_active_directory/src/callback.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Chamilo\UserBundle\Entity\User;
99

10+
$GLOBALS['noredirection'] = empty($_GET) || isset($_GET['code']) || isset($_GET['state']) || isset($_GET['session_state']) || isset($_GET['error']);
11+
1012
require __DIR__.'/../../../main/inc/global.inc.php';
1113

1214
if (!empty($_GET['error']) && !empty($_GET['state'])) {
@@ -142,4 +144,7 @@
142144
ChamiloSession::write('_user', $userInfo);
143145
ChamiloSession::write('_user_auth_source', 'azure_active_directory');
144146
Event::eventLogin($userInfo['user_id']);
147+
148+
$GLOBALS['noredirection'] = false;
149+
145150
Redirect::session_request_uri(true, $userInfo['user_id']);

0 commit comments

Comments
 (0)