From efbdc3bbd6cba8691391ec2192ea96adbfb8c029 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 19 Mar 2014 22:45:31 +0100 Subject: Initial commit --- autoload/Todo/SessionHelper.php | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 autoload/Todo/SessionHelper.php (limited to 'autoload/Todo/SessionHelper.php') diff --git a/autoload/Todo/SessionHelper.php b/autoload/Todo/SessionHelper.php new file mode 100644 index 0000000..b4811ab --- /dev/null +++ b/autoload/Todo/SessionHelper.php @@ -0,0 +1,49 @@ +user->lists(); !$l->dry(); $l->next()) { + $lists[] = array( + 'id' => $l->id, + 'name' => $l->name, + 'active' => ($l->id === $f3->get('listid')), + ); + } + $f3->set('lists', $lists); + } + + public function beforeRoute($f3) { + $id = $f3->get('SESSION.userID'); + if(is_numeric($id) && ($id > 0)) { + $this->user = new \Todo\Model\User($f3->get('DB')); + if((!$this->user->byID($id)) || (!$this->user->active)) { + $this->user = NULL; + } + } + $f3->set('listid', -1); + } + + public function afterRoute($f3) { + $f3->set('SESSION.userID', ($this->user === NULL) ? -1 : $this->user->id); + if($this->user !== NULL) { + $f3->set('user', $this->user->name); + $this->populateLists($f3); + } else { + $f3->set('user', ''); + } + } + + protected function needLogin($f3) { + if($this->user === NULL) { + $f3->set('error', 'You must be logged in to do that'); + $f3->set('content', 'blank.html'); + return true; + } + return false; + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2