diff options
-rw-r--r-- | app/Controller/Auth.php | 67 | ||||
-rw-r--r-- | app/Controller/Base.php | 2 | ||||
-rw-r--r-- | app/Controller/User.php | 60 | ||||
-rw-r--r-- | app/Model/Acl.php | 3 | ||||
-rw-r--r-- | app/Template/auth/index.php (renamed from app/Template/user/login.php) | 2 | ||||
-rw-r--r-- | app/Template/layout.php | 2 |
6 files changed, 74 insertions, 62 deletions
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 @@ +<?php + +namespace Controller; + +/** + * Authentication controller + * + * @package controller + * @author Frederic Guillot + */ +class Auth extends Base +{ + /** + * Display the form login + * + * @access public + */ + public function login(array $values = array(), array $errors = array()) + { + if ($this->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')); + } +} diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 10bf962f..f4b99a79 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -197,7 +197,7 @@ abstract class Base $this->response->text('Not Authorized', 401); } - $this->response->redirect('?controller=user&action=login&redirect_query='.urlencode($this->request->getQueryString())); + $this->response->redirect($this->helper->url('auth', 'login', array('redirect_query' => urlencode($this->request->getQueryString())))); } } diff --git a/app/Controller/User.php b/app/Controller/User.php index 5dad4ef6..37f10969 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -11,62 +11,6 @@ namespace Controller; class User extends Base { /** - * Logout and destroy session - * - * @access public - */ - public function logout() - { - $this->checkCSRFParam(); - $this->authentication->backend('rememberMe')->destroy($this->userSession->getId()); - $this->session->close(); - $this->response->redirect('?controller=user&action=login'); - } - - /** - * Display the form login - * - * @access public - */ - public function login(array $values = array(), array $errors = array()) - { - if ($this->userSession->isLogged()) { - $this->response->redirect('?controller=app'); - } - - $this->response->html($this->template->layout('user/login', 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)); - } - else { - $this->response->redirect('?controller=app'); - } - } - - $this->login($values, $errors); - } - - /** * Common layout for user views * * @access protected @@ -450,7 +394,7 @@ class User extends Base $this->response->redirect('?controller=app'); } else { - $this->response->html($this->template->layout('user/login', array( + $this->response->html($this->template->layout('auth/index', array( 'errors' => array('login' => t('Google authentication failed')), 'values' => array(), 'no_layout' => true, @@ -512,7 +456,7 @@ class User extends Base $this->response->redirect('?controller=app'); } else { - $this->response->html($this->template->layout('user/login', array( + $this->response->html($this->template->layout('auth/index', array( 'errors' => array('login' => t('GitHub authentication failed')), 'values' => array(), 'no_layout' => true, diff --git a/app/Model/Acl.php b/app/Model/Acl.php index cc4d0528..d0e7352a 100644 --- a/app/Model/Acl.php +++ b/app/Model/Acl.php @@ -17,7 +17,8 @@ class Acl extends Base * @var array */ private $public_acl = array( - 'user' => array('login', 'check', 'google', 'github'), + 'auth' => array('login', 'check'), + 'user' => array('google', 'github'), 'task' => array('readonly'), 'board' => array('readonly'), 'project' => array('feed'), diff --git a/app/Template/user/login.php b/app/Template/auth/index.php index c2e3914e..b35b1253 100644 --- a/app/Template/user/login.php +++ b/app/Template/auth/index.php @@ -4,7 +4,7 @@ <p class="alert alert-error"><?= $this->e($errors['login']) ?></p> <?php endif ?> - <form method="post" action="<?= $this->u('user', 'check', array('redirect_query' => urlencode($redirect_query))) ?>"> + <form method="post" action="<?= $this->u('auth', 'check', array('redirect_query' => $redirect_query)) ?>"> <?= $this->formCsrf() ?> diff --git a/app/Template/layout.php b/app/Template/layout.php index ec9f2288..1cdcc249 100644 --- a/app/Template/layout.php +++ b/app/Template/layout.php @@ -58,7 +58,7 @@ </li> <?php endif ?> <li> - <?= $this->a(t('Logout'), 'user', 'logout', array(), true) ?> + <?= $this->a(t('Logout'), 'auth', 'logout') ?> <span class="username hide-tablet">(<?= $this->a($this->e($this->getFullname()), 'user', 'show', array('user_id' => $this->userSession->getId())) ?>)</span> </li> </ul> |