From 9383a15af699ede77142d040b65118e15754a2ca Mon Sep 17 00:00:00 2001 From: Frédéric Guillot Date: Sat, 25 Jan 2014 14:56:02 -0500 Subject: First commit --- controllers/base.php | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 controllers/base.php (limited to 'controllers/base.php') diff --git a/controllers/base.php b/controllers/base.php new file mode 100644 index 00000000..f0ae5bd2 --- /dev/null +++ b/controllers/base.php @@ -0,0 +1,79 @@ +request = new \Request; + $this->response = new \Response; + $this->session = new \Session; + $this->template = new \Template; + $this->config = new \Model\Config; + $this->user = new \Model\User; + $this->project = new \Model\Project; + $this->task = new \Model\Task; + $this->board = new \Model\Board; + } + + public function beforeAction($controller, $action) + { + $this->session->open(); + + $public = array( + 'user' => array('login', 'check'), + 'task' => array('add'), + ); + + if (! isset($_SESSION['user']) && ! isset($public[$controller]) && ! in_array($action, $public[$controller])) { + $this->response->redirect('?controller=user&action=login'); + } + + // Load translations + $language = $this->config->get('language', 'en_US'); + if ($language !== 'en_US') \Translator\load($language); + + $this->response->csp(); + $this->response->nosniff(); + $this->response->xss(); + $this->response->hsts(); + $this->response->xframe(); + } + + public function checkPermissions() + { + if ($_SESSION['user']['is_admin'] == 0) { + $this->response->redirect('?controller=user&action=forbidden'); + } + } + + public function redirectNoProject() + { + $this->session->flash(t('There is no active project, the first step is to create a new project.')); + $this->response->redirect('?controller=project&action=create'); + } +} -- cgit v1.2.3