mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-21 20:34:57 +09:00
Redirect to login page if not logged in
This commit is contained in:
1 parent
0f7e238626
commit
b7a7b6ba8a
1 file changed
+23
-3
+23
-3
@@ -168,17 +168,37 @@ $di['twig'] = $di->factory(function () use ($di) {
|
||||
|
||||
$di['is_client_logged'] = function() use($di) {
|
||||
if(!$di['auth']->isClientLoggedIn()) {
|
||||
$url = $di['url']->link('login');
|
||||
header("Location: $url");
|
||||
throw new Exception('Client is not logged in');
|
||||
$api_str = '/api/';
|
||||
$url = $di['request']->getQuery('_url');
|
||||
if (strncasecmp($url, $api_str , strlen($api_str)) === 0) {
|
||||
//Throw Exception if api request
|
||||
throw new Exception('Client is not logged in');
|
||||
}
|
||||
else {
|
||||
//Redirect to login page if browser request
|
||||
$login_url = $di['url']->link('login');
|
||||
header("Location: $login_url");
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
$di['is_admin_logged'] = function() use($di) {
|
||||
|
||||
if(!$di['auth']->isAdminLoggedIn()) {
|
||||
$api_str = '/api/';
|
||||
$url = $di['request']->getQuery('_url');
|
||||
if (strncasecmp($url, $api_str , strlen($api_str)) === 0) {
|
||||
//Throw Exception if api request
|
||||
throw new Exception('Admin is not logged in');
|
||||
}
|
||||
else {
|
||||
//Redirect to login page if browser request
|
||||
$login_url = $di['url']->adminLink('staff/login');
|
||||
header("Location: $login_url");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user