public function __construct($route)
{
parent::__construct($route);
if ($this->checkAuth($_SESSION['uid'] ?? null)) {
$this->authRedirect($this->controller);
$this->layout = 'auth';
} else {
$this->noAuthRedirect($this->controller);
$this->layout = 'noauth';
}
}
private function checkAuth($session_uid)
{
if (isset($session_uid)) {
$this->user = $this->mObj->getUser($session_uid);
if (is_object($this->user)) {
return true;
}
session_unset();
}
return false;
}
protected function redirect($http = null)
{
if (is_null($http)) {
$redirect = $_SERVER['HTTP_REFERER'] ?? '/';
} else {
$redirect = $http;
}
header('location: ' . $redirect);
exit();
}
protected function alertRedirect($result, $text, $http = null)
{
$_SESSION['alert'] = [
'result' => $result,
'text' => $text
];
$this->redirect($http);
}
private function authRedirect($controller)
{
if ($controller == 'Start') {
$this->alertRedirect('success', 'Добро пожаловать', '/menu');
}
}
private function noAuthRedirect($controller)
{
if ($controller != 'Start') {
$this->alertRedirect('danger', 'Всего доброго', '/');
}
}
private function checkAuth($session_uid)
{
if (isset($session_uid)) {
$this->user = $this->mObj->getUser($session_uid);
if (is_object($this->user)) {
return true;
}
session_unset();
}
return false;
}
public function __construct($route)
{
parent::__construct($route);
if ($this->checkAuth($_SESSION['uid'] ?? null)) {
$this->layout = 'auth';
} else {
$this->layout = 'noauth';
}
}
private function checkAuth($session_uid)
{
if (isset($session_uid)) {
return true;
}
return false;
}