Added improved session enforcing and redirection methods
This commit is contained in:
parent
f9540b9aab
commit
a3c0ac7ab6
|
@ -40,8 +40,30 @@ function tpl_styles($styles) {
|
|||
}
|
||||
|
||||
|
||||
function cookie_redirect_app() {
|
||||
// TODO: also check if cookie is valid to redirect
|
||||
if (isset($_COOKIE['fedilove_session']))
|
||||
function session() {
|
||||
if (!isset($_COOKIE['fedilove_session']))
|
||||
return null;
|
||||
|
||||
require_once 'database.php';
|
||||
$session = null;
|
||||
if (isset($GLOBALS['db_session']))
|
||||
$session = $GLOBALS['db_session'];
|
||||
else {
|
||||
$session = (new DB())->findOne('u__sessions',
|
||||
['session' => $_COOKIE['fedilove_session']]);
|
||||
$GLOBALS['db_session'] = $session;
|
||||
}
|
||||
if ($session !== null && strlen((string)$session->_id) > 0)
|
||||
return $session;
|
||||
return null;
|
||||
}
|
||||
|
||||
function session_enforce($redirect = '/') {
|
||||
if (session() === null)
|
||||
redirect($redirect);
|
||||
}
|
||||
|
||||
function if_session_redirect_app() {
|
||||
if (session() !== null)
|
||||
redirect(APP_DIR);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?php require 'base.php' ?>
|
||||
<?php cookie_redirect_app() ?>
|
||||
<?php if_session_redirect_app() ?>
|
||||
<?php tpl('pub.header', [
|
||||
'title' => ' s(login)',
|
||||
'scripts' => ['http']
|
||||
|
|
Loading…
Reference in New Issue