mirror of
https://github.com/FOSSBilling/FOSSBilling.git
synced 2026-11-21 20:34:57 +09:00
Merge pull request #684 from samapraku/master
Redirect to login page if client or admin is not logged in
This commit is contained in:
2 files changed
+28
-5
No files matched your search
+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;
|
||||
};
|
||||
|
||||
|
||||
@@ -285,6 +285,7 @@ class Service
|
||||
public function renderString($tpl, $try_render, $vars)
|
||||
{
|
||||
$twig = $this->di['twig'];
|
||||
//add client api if _client_id is set
|
||||
if(isset($vars['_client_id'])) {
|
||||
$identity = $this->di['db']->load('Client', $vars['_client_id']);
|
||||
if($identity instanceof \Model_Client) {
|
||||
@@ -296,12 +297,14 @@ class Service
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else{
|
||||
// attempt adding admin api to twig
|
||||
try {
|
||||
$twig->addGlobal('admin', $this->di['api_admin']);
|
||||
} catch(\Exception $e) {
|
||||
//skip if admin is not logged in
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
$template = $twig->load($tpl);
|
||||
@@ -1582,4 +1585,4 @@ class Service
|
||||
$this->di['session']->delete('pending_messages');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user