fix: show access denied page for permission failures

This commit is contained in:
DevSoftTech Server 2026-08-10 12:30:32 +05:30
parent 711b093487
commit 681ad44a69
4 changed files with 68 additions and 2 deletions

View File

@ -78,8 +78,8 @@ class Auth extends ShieldAuth
'login' => '/',
'logout' => 'login',
'force_reset' => '/',
'permission_denied' => '/',
'group_denied' => '/',
'permission_denied' => 'access-denied',
'group_denied' => 'access-denied',
];
/**

View File

@ -6,6 +6,7 @@ use CodeIgniter\Router\RouteCollection;
* @var RouteCollection $routes
*/
$routes->get('/', 'Home::index');
$routes->get('access-denied', 'Home::accessDenied');
$routes->get('dashboard', 'Home::dashboard');
$routes->get('dashboard/opd', 'Home::opdDashboard');
$routes->get('dashboard/ipd', 'Home::ipdDashboard');

View File

@ -34,6 +34,18 @@ class Home extends BaseController
]);
}
public function accessDenied()
{
$authRedirect = $this->ensureAuthenticated();
if ($authRedirect !== null) {
return $authRedirect;
}
return $this->response
->setStatusCode(403)
->setBody(view('errors/html/access_denied'));
}
public function billing()
{
$authRedirect = $this->ensureAuthenticated();

View File

@ -0,0 +1,53 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Access denied</title>
<style>
:root {
color-scheme: light;
font-family: "Segoe UI", sans-serif;
background: #f4f6f8;
color: #17212b;
}
body {
min-height: 100vh;
margin: 0;
display: grid;
place-items: center;
}
main {
width: min(560px, calc(100% - 40px));
border-left: 5px solid #b42318;
background: #fff;
padding: 32px;
box-shadow: 0 8px 28px rgba(23, 33, 43, 0.12);
}
h1 {
margin: 0 0 12px;
font-size: 28px;
}
p {
margin: 0 0 24px;
line-height: 1.55;
color: #475467;
}
a {
display: inline-block;
color: #fff;
background: #175cd3;
padding: 10px 16px;
text-decoration: none;
font-weight: 600;
}
</style>
</head>
<body>
<main>
<h1>Access denied</h1>
<p>Your account does not have the permission required to open this page. Ask an administrator to verify your assigned role and its permissions.</p>
<a href="<?= esc(base_url('/')) ?>">Return to HMS</a>
</main>
</body>
</html>