summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2015-04-11 18:05:10 -0400
committerFrederic Guillot <fred@kanboard.net>2015-04-11 18:05:10 -0400
commit7df055aff1e1056d87bb720531d60cb079805f94 (patch)
treeeee8f0b873ebdebc0d87fe7b835ce0f243e6a64e /app/Controller
parentea9d402587d6fbcb39080a5d9a26e94ff4575443 (diff)
Add auth controller
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/Auth.php67
-rw-r--r--app/Controller/Base.php2
-rw-r--r--app/Controller/User.php60
3 files changed, 70 insertions, 59 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,