From 7df055aff1e1056d87bb720531d60cb079805f94 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 11 Apr 2015 18:05:10 -0400 Subject: Add auth controller --- app/Controller/Auth.php | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 app/Controller/Auth.php (limited to 'app/Controller/Auth.php') diff --git a/app/Controller/Auth.php b/app/Controller/Auth.php new file mode 100644 index 00000000..c1859304 --- /dev/null +++ b/app/Controller/Auth.php @@ -0,0 +1,67 @@ +userSession->isLogged()) { + $this->response->redirect($this->helper->url('app', 'index')); + } + + $this->response->html($this->template->layout('auth/index', array( + 'errors' => $errors, + 'values' => $values, + 'no_layout' => true, + 'redirect_query' => $this->request->getStringParam('redirect_query'), + 'title' => t('Login') + ))); + } + + /** + * Check credentials + * + * @access public + */ + public function check() + { + $redirect_query = $this->request->getStringParam('redirect_query'); + $values = $this->request->getValues(); + list($valid, $errors) = $this->authentication->validateForm($values); + + if ($valid) { + + if ($redirect_query !== '') { + $this->response->redirect('?'.urldecode($redirect_query)); + } + + $this->response->redirect($this->helper->url('app', 'index')); + } + + $this->login($values, $errors); + } + + /** + * Logout and destroy session + * + * @access public + */ + public function logout() + { + $this->authentication->backend('rememberMe')->destroy($this->userSession->getId()); + $this->session->close(); + $this->response->redirect($this->helper->url('auth', 'login')); + } +} -- cgit v1.2.3