diff options
Diffstat (limited to 'w/class/controller.php')
-rw-r--r-- | w/class/controller.php | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/w/class/controller.php b/w/class/controller.php index 6eab6e4..62b1f49 100644 --- a/w/class/controller.php +++ b/w/class/controller.php @@ -1,16 +1,16 @@ <?php -class Controller extends Application +class Controller { protected $user; protected $usermanager; - protected $templates; + protected $plates; public function __construct() { - parent::__construct(); $this->setuser(); - $this->settemplate(); + $this->initplates(); + $this->initconfig(); } @@ -21,9 +21,9 @@ class Controller extends Application $this->user = $this->usermanager->readsession(); } - public function settemplate() + public function initplates() { - $this->templates = new League\Plates\Engine(Model::TEMPLATES_DIR); + $this->plates = new League\Plates\Engine(Model::TEMPLATES_DIR); } public function useriseditor() @@ -37,6 +37,47 @@ class Controller extends Application } } + 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); + } + } |