From d7f3313ff4514e38c9f53439cd1a1287e56e45f7 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Sun, 11 Nov 2018 17:19:26 +0100 Subject: reboot folder --- app/class/controller.php | 96 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 app/class/controller.php (limited to 'app/class/controller.php') diff --git a/app/class/controller.php b/app/class/controller.php new file mode 100644 index 0000000..c97c99f --- /dev/null +++ b/app/class/controller.php @@ -0,0 +1,96 @@ +setuser(); + $this->initplates(); + $this->initconfig(); + } + + public function setuser() + { + $this->usermanager = new Modeluser; + $this->user = $this->usermanager->readsession(); + } + + public function initplates() + { + $this->plates = new League\Plates\Engine(Model::TEMPLATES_DIR); + } + + public function useriseditor() + { + if ($this->user->level() >= $this->usermanager::EDITOR) { + echo '

Editor access

'; + return true; + } else { + echo '

Not enought rights to see more...

'; + return false; + } + } + + public function initconfig() + { + Config::readconfig(); + } + + public function showtemplate($template, $params) + { + $params = array_merge($this->commonsparams(), $params); + echo $this->plates->render($template, $params); + } + + public function commonsparams() + { + $commonsparams = []; + $commonsparams['user'] = $this->user; + return $commonsparams; + } + + public function login($redirect = 'home') + { + if(isset($_POST['pass'])) { + $this->user = $this->usermanager->login($_POST['pass']); + $this->usermanager->writesession($this->user); + } + if($redirect == 'art') { + $this->redirect('?id=' . $this->art->id()); + } else { + $this->redirect('?aff=' . $redirect); + } + } + + public function logout($redirect = 'home') + { + $this->user = $this->usermanager->logout(); + $this->usermanager->writesession($this->user); + if($redirect == 'art') { + $this->redirect('?id=' . $this->art->id()); + } else { + $this->redirect('?aff=' . $redirect); + } + } + + + + + public function redirect($url) + { + header('Location: ' . $url); + } + + + +} + + + + + +?> \ No newline at end of file -- cgit v1.2.3