diff options
author | Frédéric Guillot <fguillot@users.noreply.github.com> | 2014-04-19 22:12:12 -0400 |
---|---|---|
committer | Frédéric Guillot <fguillot@users.noreply.github.com> | 2014-04-19 22:12:12 -0400 |
commit | a04ecbde778decfdea7200806a6b1144861ae05f (patch) | |
tree | e4670e3013734d9c7bd201f5d6ef1fbaae13d3b5 /controllers | |
parent | 5aacb6a76351889a6ec5ed01c8e80f139c2b2027 (diff) |
Add RememberMe feature and authentications history
Diffstat (limited to 'controllers')
-rw-r--r-- | controllers/action.php | 2 | ||||
-rw-r--r-- | controllers/app.php | 11 | ||||
-rw-r--r-- | controllers/base.php | 28 | ||||
-rw-r--r-- | controllers/config.php | 19 | ||||
-rw-r--r-- | controllers/project.php | 90 | ||||
-rw-r--r-- | controllers/user.php | 13 |
6 files changed, 141 insertions, 22 deletions
diff --git a/controllers/action.php b/controllers/action.php index 32ec737d..b4006940 100644 --- a/controllers/action.php +++ b/controllers/action.php @@ -7,7 +7,7 @@ require_once __DIR__.'/base.php'; /** * Automatic actions management * - * @package controllers + * @package controller * @author Frederic Guillot */ class Action extends Base diff --git a/controllers/app.php b/controllers/app.php index e72ac9d0..68872a48 100644 --- a/controllers/app.php +++ b/controllers/app.php @@ -4,8 +4,19 @@ namespace Controller; require_once __DIR__.'/base.php'; +/** + * Application controller + * + * @package controller + * @author Frederic Guillot + */ class App extends Base { + /** + * Redirect to the project creation page or the board controller + * + * @access public + */ public function index() { if ($this->project->countByStatus(\Model\Project::ACTIVE)) { diff --git a/controllers/base.php b/controllers/base.php index cb76cc05..5f482f7e 100644 --- a/controllers/base.php +++ b/controllers/base.php @@ -26,6 +26,8 @@ abstract class Base $this->task = $registry->task; $this->user = $registry->user; $this->comment = $registry->comment; + $this->rememberMe = $registry->rememberMe; + $this->lastLogin = $registry->lastLogin; $this->event = $registry->shared('event'); } @@ -37,7 +39,7 @@ abstract class Base public function beforeAction($controller, $action) { // Start the session - $this->session->open(dirname($_SERVER['PHP_SELF']), SESSION_SAVE_PATH); + $this->session->open(BASE_URL_DIRECTORY, SESSION_SAVE_PATH); // HTTP secure headers $this->response->csp(); @@ -53,9 +55,27 @@ abstract class Base // Set timezone date_default_timezone_set($this->config->get('timezone', 'UTC')); - // If the user is not authenticated redirect to the login form, if the action is public continue - if (! isset($_SESSION['user']) && ! $this->acl->isPublicAction($controller, $action)) { - $this->response->redirect('?controller=user&action=login'); + // Authentication + if (! $this->acl->isLogged() && ! $this->acl->isPublicAction($controller, $action)) { + + // Try the remember me authentication first + if (! $this->rememberMe->authenticate()) { + + // Redirect to the login form if not authenticated + $this->response->redirect('?controller=user&action=login'); + } + else { + + $this->lastLogin->create( + \Model\LastLogin::AUTH_REMEMBER_ME, + $this->acl->getUserId(), + $this->user->getIpAddress(), + $this->user->getUserAgent() + ); + } + } + else if ($this->rememberMe->hasCookie()) { + $this->rememberMe->refresh(); } // Check if the user is allowed to see this page diff --git a/controllers/config.php b/controllers/config.php index 0adf1d54..527c8a4c 100644 --- a/controllers/config.php +++ b/controllers/config.php @@ -28,7 +28,9 @@ class Config extends Base 'errors' => array(), 'menu' => 'config', 'title' => t('Settings'), - 'timezones' => $this->config->getTimezones() + 'timezones' => $this->config->getTimezones(), + 'remember_me_sessions' => $this->rememberMe->getAll($this->acl->getUserId()), + 'last_logins' => $this->lastLogin->getAll($this->acl->getUserId()), ))); } @@ -63,7 +65,9 @@ class Config extends Base 'errors' => $errors, 'menu' => 'config', 'title' => t('Settings'), - 'timezones' => $this->config->getTimezones() + 'timezones' => $this->config->getTimezones(), + 'remember_me_sessions' => $this->rememberMe->getAll($this->acl->getUserId()), + 'last_logins' => $this->lastLogin->getAll($this->acl->getUserId()), ))); } @@ -101,4 +105,15 @@ class Config extends Base $this->session->flash(t('All tokens have been regenerated.')); $this->response->redirect('?controller=config'); } + + /** + * Remove a "RememberMe" token + * + * @access public + */ + public function removeRememberMeToken() + { + $this->rememberMe->remove($this->request->getIntegerParam('id')); + $this->response->redirect('?controller=config&action=index#remember-me'); + } } diff --git a/controllers/project.php b/controllers/project.php index 5cc9f5d1..a89c7879 100644 --- a/controllers/project.php +++ b/controllers/project.php @@ -4,9 +4,19 @@ namespace Controller; require_once __DIR__.'/base.php'; +/** + * Project controller + * + * @package controller + * @author Frederic Guillot + */ class Project extends Base { - // Display access forbidden page + /** + * Display access forbidden page + * + * @access public + */ public function forbidden() { $this->response->html($this->template->layout('project_forbidden', array( @@ -15,7 +25,11 @@ class Project extends Base ))); } - // List of completed tasks for a given project + /** + * List of completed tasks for a given project + * + * @access public + */ public function tasks() { $project_id = $this->request->getIntegerParam('project_id'); @@ -40,7 +54,11 @@ class Project extends Base ))); } - // List of projects + /** + * List of projects + * + * @access public + */ public function index() { $projects = $this->project->getAll(true, $this->acl->isRegularUser()); @@ -54,7 +72,11 @@ class Project extends Base ))); } - // Display a form to create a new project + /** + * Display a form to create a new project + * + * @access public + */ public function create() { $this->response->html($this->template->layout('project_new', array( @@ -65,7 +87,11 @@ class Project extends Base ))); } - // Validate and save a new project + /** + * Validate and save a new project + * + * @access public + */ public function save() { $values = $this->request->getValues(); @@ -90,7 +116,11 @@ class Project extends Base ))); } - // Display a form to edit a project + /** + * Display a form to edit a project + * + * @access public + */ public function edit() { $project = $this->project->getById($this->request->getIntegerParam('project_id')); @@ -108,7 +138,11 @@ class Project extends Base ))); } - // Validate and update a project + /** + * Validate and update a project + * + * @access public + */ public function update() { $values = $this->request->getValues() + array('is_active' => 0); @@ -133,7 +167,11 @@ class Project extends Base ))); } - // Confirmation dialog before to remove a project + /** + * Confirmation dialog before to remove a project + * + * @access public + */ public function confirm() { $project = $this->project->getById($this->request->getIntegerParam('project_id')); @@ -150,7 +188,11 @@ class Project extends Base ))); } - // Remove a project + /** + * Remove a project + * + * @access public + */ public function remove() { $project_id = $this->request->getIntegerParam('project_id'); @@ -164,7 +206,11 @@ class Project extends Base $this->response->redirect('?controller=project'); } - // Enable a project + /** + * Enable a project + * + * @access public + */ public function enable() { $project_id = $this->request->getIntegerParam('project_id'); @@ -178,7 +224,11 @@ class Project extends Base $this->response->redirect('?controller=project'); } - // Disable a project + /** + * Disable a project + * + * @access public + */ public function disable() { $project_id = $this->request->getIntegerParam('project_id'); @@ -192,7 +242,11 @@ class Project extends Base $this->response->redirect('?controller=project'); } - // Users list for the selected project + /** + * Users list for the selected project + * + * @access public + */ public function users() { $project = $this->project->getById($this->request->getIntegerParam('project_id')); @@ -210,7 +264,11 @@ class Project extends Base ))); } - // Allow a specific user for the selected project + /** + * Allow a specific user for the selected project + * + * @access public + */ public function allow() { $values = $this->request->getValues(); @@ -229,7 +287,11 @@ class Project extends Base $this->response->redirect('?controller=project&action=users&project_id='.$values['project_id']); } - // Revoke user access + /** + * Revoke user access + * + * @access public + */ public function revoke() { $values = array( diff --git a/controllers/user.php b/controllers/user.php index bc5c48fe..9e964a4e 100644 --- a/controllers/user.php +++ b/controllers/user.php @@ -32,6 +32,7 @@ class User extends Base */ public function logout() { + $this->rememberMe->destroy($this->acl->getUserId()); $this->session->close(); $this->response->redirect('?controller=user&action=login'); } @@ -63,7 +64,17 @@ class User extends Base $values = $this->request->getValues(); list($valid, $errors) = $this->user->validateLogin($values); - if ($valid) $this->response->redirect('?controller=app'); + if ($valid) { + + $this->lastLogin->create( + \Model\LastLogin::AUTH_DATABASE, + $this->acl->getUserId(), + $this->user->getIpAddress(), + $this->user->getUserAgent() + ); + + $this->response->redirect('?controller=app'); + } $this->response->html($this->template->layout('user_login', array( 'errors' => $errors, |