aboutsummaryrefslogtreecommitdiff
path: root/app/class/Controller.php
diff options
context:
space:
mode:
authorvincent-peugnet <v.peugnet@free.fr>2020-04-28 14:20:10 +0200
committervincent-peugnet <v.peugnet@free.fr>2020-04-28 20:21:34 +0200
commit98514a4e0037aa0879e45bbad660aeda8837c624 (patch)
treea574e7cf6a53150e1d960fc9b4520a49567b04bd /app/class/Controller.php
parentcba95c5eb19a33654a6f0995c6f9e0885b7afc20 (diff)
downloadwcms-98514a4e0037aa0879e45bbad660aeda8837c624.tar.gz
wcms-98514a4e0037aa0879e45bbad660aeda8837c624.zip
add session as controller var
Diffstat (limited to 'app/class/Controller.php')
-rw-r--r--app/class/Controller.php20
1 files changed, 18 insertions, 2 deletions
diff --git a/app/class/Controller.php b/app/class/Controller.php
index 7bfa3a2..56d4dfe 100644
--- a/app/class/Controller.php
+++ b/app/class/Controller.php
@@ -7,9 +7,13 @@ use DateTimeImmutable;
use Exception;
use InvalidArgumentException;
use League\Plates\Engine;
+use Throwable;
class Controller
{
+ /** @var Session */
+ protected $session;
+
/** @var User */
protected $user;
@@ -29,6 +33,9 @@ class Controller
public function __construct($router)
{
+ $this->session = new Session($_SESSION['user' . Config::basepath()] ?? []);
+ $this->usermanager = new Modeluser();
+
$this->setuser();
$this->router = $router;
$this->pagemanager = new Modelpage();
@@ -38,8 +45,17 @@ class Controller
public function setuser()
{
- $this->usermanager = new Modeluser();
- $this->user = $this->usermanager->readsession();
+ if (empty($this->session->user)) {
+ $this->user = new User();
+ } else {
+ if (!$this->user = $this->usermanager->get($this->session->user)) {
+ if (!$this->user = $this->usermanager->readcookie()) {
+ $this->user = new User();
+ } else {
+ $this->session->addtosession('user', $this->user->id());
+ }
+ }
+ }
}
public function initplates()