Skip to content

Commit

Permalink
chore: Support rendering custom message on logged in 401 page
Browse files Browse the repository at this point in the history
  • Loading branch information
hellopablo committed Jun 20, 2024
1 parent d39334c commit 4d44f82
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/Common/Service/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,15 +328,29 @@ public function show401(
bool $bForceView = false
): void {

/** @var UserFeedback $oSession */
$oUserFeedback = Factory::service('UserFeedback');
/** @var Input $oInput */
$oInput = Factory::service('Input');

// --------------------------------------------------------------------------

if ($bForceView || (function_exists('isLoggedIn') && isLoggedIn())) {

if ($bLogError) {
$sPage = ArrayHelper::get('REQUEST_URI', $_SERVER);
log_message('error', '401 Unauthorised --> ' . $sPage);
}

$sMessage = 'The page you are trying to view is restricted. Sadly you do not have enough ';
$sMessage .= 'permissions to see its content.';
if (!is_null($sFlashMessage)) {
$sMessage = $sFlashMessage;

} elseif ($oUserFeedback->issetError()) {
$sMessage = $oUserFeedback->getError();

} else {
$sMessage = 'The page you are trying to view is restricted. Sadly you do not have enough permissions to see its content.';
}

// --------------------------------------------------------------------------

Expand All @@ -359,11 +373,6 @@ public function show401(

} else {

/** @var UserFeedback $oSession */
$oUserFeedback = Factory::service('UserFeedback');
/** @var Input $oInput */
$oInput = Factory::service('Input');

if (!is_null($sFlashMessage)) {
$oUserFeedback->error($sFlashMessage);
} elseif (!$oUserFeedback->issetError()) {
Expand Down

0 comments on commit 4d44f82

Please sign in to comment.