diff --git a/ChangeLog b/ChangeLog index 554176534..7d10c2c3e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,11 @@ Improvements: * Improve error handling of plugins +Internal code refactoring: + +* Rewrite of session management +* Move some classes to a new namespace Kanboard\Core\Http + Bug fixes: * Loading cs_CZ locale display the wrong language in datetime picker diff --git a/app/Api/Auth.php b/app/Api/Auth.php index b3627e4b3..a084d6eb5 100644 --- a/app/Api/Auth.php +++ b/app/Api/Auth.php @@ -28,7 +28,7 @@ class Auth extends Base if ($username !== 'jsonrpc' && ! $this->authentication->hasCaptcha($username) && $this->authentication->authenticate($username, $password)) { $this->checkProcedurePermission(true, $method); - $this->userSession->refresh($this->user->getByUsername($username)); + $this->userSession->initialize($this->user->getByUsername($username)); } elseif ($username === 'jsonrpc' && $password === $this->config->get('api_token')) { $this->checkProcedurePermission(false, $method); } else { diff --git a/app/Api/Me.php b/app/Api/Me.php index 2c332a8c3..2c4161fd5 100644 --- a/app/Api/Me.php +++ b/app/Api/Me.php @@ -14,7 +14,7 @@ class Me extends Base { public function getMe() { - return $this->session['user']; + return $this->sessionStorage->user; } public function getMyDashboard() diff --git a/app/Auth/Database.php b/app/Auth/Database.php index 91b17a5fa..c2041d4d8 100644 --- a/app/Auth/Database.php +++ b/app/Auth/Database.php @@ -39,7 +39,7 @@ class Database extends Base ->findOne(); if (is_array($user) && password_verify($password, $user['password'])) { - $this->userSession->refresh($user); + $this->userSession->initialize($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; } diff --git a/app/Auth/Github.php b/app/Auth/Github.php index b89dc5b80..4777152a7 100644 --- a/app/Auth/Github.php +++ b/app/Auth/Github.php @@ -39,7 +39,7 @@ class Github extends Base $user = $this->user->getByGithubId($github_id); if (! empty($user)) { - $this->userSession->refresh($user); + $this->userSession->initialize($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; } diff --git a/app/Auth/Gitlab.php b/app/Auth/Gitlab.php index a59bc1fa0..698b59c3a 100644 --- a/app/Auth/Gitlab.php +++ b/app/Auth/Gitlab.php @@ -39,7 +39,7 @@ class Gitlab extends Base $user = $this->user->getByGitlabId($gitlab_id); if (! empty($user)) { - $this->userSession->refresh($user); + $this->userSession->initialize($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; } diff --git a/app/Auth/Google.php b/app/Auth/Google.php index 32bcb4b11..6c1bc3cd2 100644 --- a/app/Auth/Google.php +++ b/app/Auth/Google.php @@ -40,7 +40,7 @@ class Google extends Base $user = $this->user->getByGoogleId($google_id); if (! empty($user)) { - $this->userSession->refresh($user); + $this->userSession->initialize($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; } diff --git a/app/Auth/Ldap.php b/app/Auth/Ldap.php index c252be17a..3d361aa7a 100644 --- a/app/Auth/Ldap.php +++ b/app/Auth/Ldap.php @@ -237,7 +237,7 @@ class Ldap extends Base } // We open the session - $this->userSession->refresh($user); + $this->userSession->initialize($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; diff --git a/app/Auth/RememberMe.php b/app/Auth/RememberMe.php index fd8ed8bb4..0a567cbe9 100644 --- a/app/Auth/RememberMe.php +++ b/app/Auth/RememberMe.php @@ -101,10 +101,10 @@ class RememberMe extends Base ); // Create the session - $this->userSession->refresh($this->user->getById($record['user_id'])); + $this->userSession->initialize($this->user->getById($record['user_id'])); // Do not ask 2FA for remember me session - $this->session['2fa_validated'] = true; + $this->sessionStorage->postAuth['validated'] = true; $this->container['dispatcher']->dispatch( 'auth.success', diff --git a/app/Auth/ReverseProxy.php b/app/Auth/ReverseProxy.php index 1910ad354..d119ca98a 100644 --- a/app/Auth/ReverseProxy.php +++ b/app/Auth/ReverseProxy.php @@ -48,7 +48,7 @@ class ReverseProxy extends Base $user = $this->user->getByUsername($login); } - $this->userSession->refresh($user); + $this->userSession->initialize($user); $this->container['dispatcher']->dispatch('auth.success', new AuthEvent(self::AUTH_NAME, $user['id'])); return true; diff --git a/app/Controller/Action.php b/app/Controller/Action.php index 37d1c2489..ad1360671 100644 --- a/app/Controller/Action.php +++ b/app/Controller/Action.php @@ -119,9 +119,9 @@ class Action extends Base if ($valid) { if ($this->action->create($values) !== false) { - $this->session->flash(t('Your automatic action have been created successfully.')); + $this->flash->success(t('Your automatic action have been created successfully.')); } else { - $this->session->flashError(t('Unable to create your automatic action.')); + $this->flash->failure(t('Unable to create your automatic action.')); } } @@ -158,9 +158,9 @@ class Action extends Base $action = $this->action->getById($this->request->getIntegerParam('action_id')); if (! empty($action) && $this->action->remove($action['id'])) { - $this->session->flash(t('Action removed successfully.')); + $this->flash->success(t('Action removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this action.')); + $this->flash->failure(t('Unable to remove this action.')); } $this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id']))); diff --git a/app/Controller/Auth.php b/app/Controller/Auth.php index 95ad8d9ee..b90e756d1 100644 --- a/app/Controller/Auth.php +++ b/app/Controller/Auth.php @@ -43,9 +43,11 @@ class Auth extends Base list($valid, $errors) = $this->authentication->validateForm($values); if ($valid) { - if (! empty($this->session['login_redirect']) && ! filter_var($this->session['login_redirect'], FILTER_VALIDATE_URL)) { - $redirect = $this->session['login_redirect']; - unset($this->session['login_redirect']); + if (isset($this->sessionStorage->redirectAfterLogin) + && ! empty($this->sessionStorage->redirectAfterLogin) + && ! filter_var($this->sessionStorage->redirectAfterLogin, FILTER_VALIDATE_URL)) { + $redirect = $this->sessionStorage->redirectAfterLogin; + unset($this->sessionStorage->redirectAfterLogin); $this->response->redirect($redirect); } @@ -63,7 +65,7 @@ class Auth extends Base public function logout() { $this->authentication->backend('rememberMe')->destroy($this->userSession->getId()); - $this->session->close(); + $this->sessionManager->close(); $this->response->redirect($this->helper->url->to('auth', 'login')); } @@ -78,7 +80,7 @@ class Auth extends Base $builder = new CaptchaBuilder; $builder->build(); - $this->session['captcha'] = $builder->getPhrase(); + $this->sessionStorage->captcha = $builder->getPhrase(); $builder->output(); } } diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 829e0ad2d..8630f00c1 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -76,8 +76,7 @@ abstract class Base extends \Kanboard\Core\Base */ public function beforeAction($controller, $action) { - // Start the session - $this->session->open($this->helper->url->dir()); + $this->sessionManager->open(); $this->sendHeaders($action); $this->container['dispatcher']->dispatch('session.bootstrap', new Event); @@ -86,7 +85,7 @@ abstract class Base extends \Kanboard\Core\Base $this->handle2FA($controller, $action); $this->handleAuthorization($controller, $action); - $this->session['has_subtask_inprogress'] = $this->subtask->hasSubtaskInProgress($this->userSession->getId()); + $this->sessionStorage->hasSubtaskInProgress = $this->subtask->hasSubtaskInProgress($this->userSession->getId()); } } @@ -102,7 +101,7 @@ abstract class Base extends \Kanboard\Core\Base $this->response->text('Not Authorized', 401); } - $this->session['login_redirect'] = $this->request->getUri(); + $this->sessionStorage->redirectAfterLogin = $this->request->getUri(); $this->response->redirect($this->helper->url->to('auth', 'login')); } } @@ -269,7 +268,7 @@ abstract class Base extends \Kanboard\Core\Base $project = $this->project->getById($project_id); if (empty($project)) { - $this->session->flashError(t('Project not found.')); + $this->flash->failure(t('Project not found.')); $this->response->redirect($this->helper->url->to('project', 'index')); } diff --git a/app/Controller/Board.php b/app/Controller/Board.php index 2d75db893..7442ff220 100644 --- a/app/Controller/Board.php +++ b/app/Controller/Board.php @@ -242,9 +242,9 @@ class Board extends Base list($valid, ) = $this->taskValidator->validateAssigneeModification($values); if ($valid && $this->taskModification->update($values)) { - $this->session->flash(t('Task updated successfully.')); + $this->flash->success(t('Task updated successfully.')); } else { - $this->session->flashError(t('Unable to update your task.')); + $this->flash->failure(t('Unable to update your task.')); } $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id']))); @@ -279,9 +279,9 @@ class Board extends Base list($valid, ) = $this->taskValidator->validateCategoryModification($values); if ($valid && $this->taskModification->update($values)) { - $this->session->flash(t('Task updated successfully.')); + $this->flash->success(t('Task updated successfully.')); } else { - $this->session->flashError(t('Unable to update your task.')); + $this->flash->failure(t('Unable to update your task.')); } $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id']))); diff --git a/app/Controller/Category.php b/app/Controller/Category.php index 4aefd9fed..9864348c9 100644 --- a/app/Controller/Category.php +++ b/app/Controller/Category.php @@ -22,7 +22,7 @@ class Category extends Base $category = $this->category->getById($this->request->getIntegerParam('category_id')); if (empty($category)) { - $this->session->flashError(t('Category not found.')); + $this->flash->failure(t('Category not found.')); $this->response->redirect($this->helper->url->to('category', 'index', array('project_id' => $project_id))); } @@ -61,10 +61,10 @@ class Category extends Base if ($valid) { if ($this->category->create($values)) { - $this->session->flash(t('Your category have been created successfully.')); + $this->flash->success(t('Your category have been created successfully.')); $this->response->redirect($this->helper->url->to('category', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to create your category.')); + $this->flash->failure(t('Unable to create your category.')); } } @@ -103,10 +103,10 @@ class Category extends Base if ($valid) { if ($this->category->update($values)) { - $this->session->flash(t('Your category have been updated successfully.')); + $this->flash->success(t('Your category have been updated successfully.')); $this->response->redirect($this->helper->url->to('category', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to update your category.')); + $this->flash->failure(t('Unable to update your category.')); } } @@ -142,9 +142,9 @@ class Category extends Base $category = $this->getCategory($project['id']); if ($this->category->remove($category['id'])) { - $this->session->flash(t('Category removed successfully.')); + $this->flash->success(t('Category removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this category.')); + $this->flash->failure(t('Unable to remove this category.')); } $this->response->redirect($this->helper->url->to('category', 'index', array('project_id' => $project['id']))); diff --git a/app/Controller/Column.php b/app/Controller/Column.php index d28fb2934..b484fe127 100644 --- a/app/Controller/Column.php +++ b/app/Controller/Column.php @@ -55,10 +55,10 @@ class Column extends Base if ($valid) { if ($this->board->addColumn($project['id'], $data['title'], $data['task_limit'], $data['description'])) { - $this->session->flash(t('Board updated successfully.')); + $this->flash->success(t('Board updated successfully.')); $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to update this board.')); + $this->flash->failure(t('Unable to update this board.')); } } @@ -98,10 +98,10 @@ class Column extends Base if ($valid) { if ($this->board->updateColumn($values['id'], $values['title'], $values['task_limit'], $values['description'])) { - $this->session->flash(t('Board updated successfully.')); + $this->flash->success(t('Board updated successfully.')); $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to update this board.')); + $this->flash->failure(t('Unable to update this board.')); } } @@ -155,9 +155,9 @@ class Column extends Base $column = $this->board->getColumn($this->request->getIntegerParam('column_id')); if (! empty($column) && $this->board->removeColumn($column['id'])) { - $this->session->flash(t('Column removed successfully.')); + $this->flash->success(t('Column removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this column.')); + $this->flash->failure(t('Unable to remove this column.')); } $this->response->redirect($this->helper->url->to('column', 'index', array('project_id' => $project['id']))); diff --git a/app/Controller/Comment.php b/app/Controller/Comment.php index d6cbbf1ee..54339e485 100644 --- a/app/Controller/Comment.php +++ b/app/Controller/Comment.php @@ -82,9 +82,9 @@ class Comment extends Base if ($valid) { if ($this->comment->create($values)) { - $this->session->flash(t('Comment added successfully.')); + $this->flash->success(t('Comment added successfully.')); } else { - $this->session->flashError(t('Unable to create your comment.')); + $this->flash->failure(t('Unable to create your comment.')); } if ($ajax) { @@ -131,9 +131,9 @@ class Comment extends Base if ($valid) { if ($this->comment->update($values)) { - $this->session->flash(t('Comment updated successfully.')); + $this->flash->success(t('Comment updated successfully.')); } else { - $this->session->flashError(t('Unable to update your comment.')); + $this->flash->failure(t('Unable to update your comment.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comment-'.$comment['id'])); @@ -171,9 +171,9 @@ class Comment extends Base $comment = $this->getComment(); if ($this->comment->remove($comment['id'])) { - $this->session->flash(t('Comment removed successfully.')); + $this->flash->success(t('Comment removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this comment.')); + $this->flash->failure(t('Unable to remove this comment.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']), 'comments')); diff --git a/app/Controller/Config.php b/app/Controller/Config.php index 47b844e48..498061442 100644 --- a/app/Controller/Config.php +++ b/app/Controller/Config.php @@ -53,9 +53,9 @@ class Config extends Base if ($this->config->save($values)) { $this->config->reload(); - $this->session->flash(t('Settings saved successfully.')); + $this->flash->success(t('Settings saved successfully.')); } else { - $this->session->flashError(t('Unable to save your settings.')); + $this->flash->failure(t('Unable to save your settings.')); } $this->response->redirect($this->helper->url->to('config', $redirect)); @@ -210,7 +210,7 @@ class Config extends Base { $this->checkCSRFParam(); $this->config->optimizeDatabase(); - $this->session->flash(t('Database optimization done.')); + $this->flash->success(t('Database optimization done.')); $this->response->redirect($this->helper->url->to('config', 'index')); } @@ -226,7 +226,7 @@ class Config extends Base $this->checkCSRFParam(); $this->config->regenerateToken($type.'_token'); - $this->session->flash(t('Token regenerated.')); + $this->flash->success(t('Token regenerated.')); $this->response->redirect($this->helper->url->to('config', $type)); } } diff --git a/app/Controller/Currency.php b/app/Controller/Currency.php index 9d6b02490..118b2c41e 100644 --- a/app/Controller/Currency.php +++ b/app/Controller/Currency.php @@ -55,10 +55,10 @@ class Currency extends Base if ($valid) { if ($this->currency->create($values['currency'], $values['rate'])) { - $this->session->flash(t('The currency rate have been added successfully.')); + $this->flash->success(t('The currency rate have been added successfully.')); $this->response->redirect($this->helper->url->to('currency', 'index')); } else { - $this->session->flashError(t('Unable to add this currency rate.')); + $this->flash->failure(t('Unable to add this currency rate.')); } } @@ -76,9 +76,9 @@ class Currency extends Base if ($this->config->save($values)) { $this->config->reload(); - $this->session->flash(t('Settings saved successfully.')); + $this->flash->success(t('Settings saved successfully.')); } else { - $this->session->flashError(t('Unable to save your settings.')); + $this->flash->failure(t('Unable to save your settings.')); } $this->response->redirect($this->helper->url->to('currency', 'index')); diff --git a/app/Controller/Customfilter.php b/app/Controller/Customfilter.php index a152c6689..d68631034 100644 --- a/app/Controller/Customfilter.php +++ b/app/Controller/Customfilter.php @@ -44,10 +44,10 @@ class Customfilter extends Base if ($valid) { if ($this->customFilter->create($values)) { - $this->session->flash(t('Your custom filter have been created successfully.')); + $this->flash->success(t('Your custom filter have been created successfully.')); $this->response->redirect($this->helper->url->to('customfilter', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to create your custom filter.')); + $this->flash->failure(t('Unable to create your custom filter.')); } } @@ -68,9 +68,9 @@ class Customfilter extends Base $this->checkPermission($project, $filter); if ($this->customFilter->remove($filter['id'])) { - $this->session->flash(t('Custom filter removed successfully.')); + $this->flash->success(t('Custom filter removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this custom filter.')); + $this->flash->failure(t('Unable to remove this custom filter.')); } $this->response->redirect($this->helper->url->to('customfilter', 'index', array('project_id' => $project['id']))); @@ -123,10 +123,10 @@ class Customfilter extends Base if ($valid) { if ($this->customFilter->update($values)) { - $this->session->flash(t('Your custom filter have been updated successfully.')); + $this->flash->success(t('Your custom filter have been updated successfully.')); $this->response->redirect($this->helper->url->to('customfilter', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to update custom filter.')); + $this->flash->failure(t('Unable to update custom filter.')); } } diff --git a/app/Controller/File.php b/app/Controller/File.php index 4d771e2fb..b46f7d193 100644 --- a/app/Controller/File.php +++ b/app/Controller/File.php @@ -22,7 +22,7 @@ class File extends Base $task = $this->getTask(); if ($this->request->isPost() && $this->file->uploadScreenshot($task['project_id'], $task['id'], $this->request->getValue('screenshot')) !== false) { - $this->session->flash(t('Screenshot uploaded successfully.')); + $this->flash->success(t('Screenshot uploaded successfully.')); if ($this->request->getStringParam('redirect') === 'board') { $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); @@ -62,7 +62,7 @@ class File extends Base $task = $this->getTask(); if (! $this->file->uploadFiles($task['project_id'], $task['id'], 'files')) { - $this->session->flashError(t('Unable to upload the file.')); + $this->flash->failure(t('Unable to upload the file.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); @@ -166,9 +166,9 @@ class File extends Base $file = $this->file->getById($this->request->getIntegerParam('file_id')); if ($file['task_id'] == $task['id'] && $this->file->remove($file['id'])) { - $this->session->flash(t('File removed successfully.')); + $this->flash->success(t('File removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this file.')); + $this->flash->failure(t('Unable to remove this file.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); diff --git a/app/Controller/Gantt.php b/app/Controller/Gantt.php index 24d94f02f..bd3d92f75 100644 --- a/app/Controller/Gantt.php +++ b/app/Controller/Gantt.php @@ -135,10 +135,10 @@ class Gantt extends Base $task_id = $this->taskCreation->create($values); if ($task_id !== false) { - $this->session->flash(t('Task created successfully.')); + $this->flash->success(t('Task created successfully.')); $this->response->redirect($this->helper->url->to('gantt', 'project', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to create your task.')); + $this->flash->failure(t('Unable to create your task.')); } } diff --git a/app/Controller/Link.php b/app/Controller/Link.php index 0eb3d679e..c7f18230e 100644 --- a/app/Controller/Link.php +++ b/app/Controller/Link.php @@ -71,10 +71,10 @@ class Link extends Base if ($valid) { if ($this->link->create($values['label'], $values['opposite_label']) !== false) { - $this->session->flash(t('Link added successfully.')); + $this->flash->success(t('Link added successfully.')); $this->response->redirect($this->helper->url->to('link', 'index')); } else { - $this->session->flashError(t('Unable to create your link.')); + $this->flash->failure(t('Unable to create your link.')); } } @@ -112,10 +112,10 @@ class Link extends Base if ($valid) { if ($this->link->update($values)) { - $this->session->flash(t('Link updated successfully.')); + $this->flash->success(t('Link updated successfully.')); $this->response->redirect($this->helper->url->to('link', 'index')); } else { - $this->session->flashError(t('Unable to update your link.')); + $this->flash->failure(t('Unable to update your link.')); } } @@ -148,9 +148,9 @@ class Link extends Base $link = $this->getLink(); if ($this->link->remove($link['id'])) { - $this->session->flash(t('Link removed successfully.')); + $this->flash->success(t('Link removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this link.')); + $this->flash->failure(t('Unable to remove this link.')); } $this->response->redirect($this->helper->url->to('link', 'index')); diff --git a/app/Controller/Oauth.php b/app/Controller/Oauth.php index 8c701cf76..395461482 100644 --- a/app/Controller/Oauth.php +++ b/app/Controller/Oauth.php @@ -51,9 +51,9 @@ class Oauth extends Base $this->checkCSRFParam(); if ($this->authentication->backend($backend)->unlink($this->userSession->getId())) { - $this->session->flash(t('Your external account is not linked anymore to your profile.')); + $this->flash->success(t('Your external account is not linked anymore to your profile.')); } else { - $this->session->flashError(t('Unable to unlink your external account.')); + $this->flash->failure(t('Unable to unlink your external account.')); } $this->response->redirect($this->helper->url->to('user', 'external', array('user_id' => $this->userSession->getId()))); @@ -99,9 +99,9 @@ class Oauth extends Base private function link($backend, $profile) { if (empty($profile)) { - $this->session->flashError(t('External authentication failed')); + $this->flash->failure(t('External authentication failed')); } else { - $this->session->flash(t('Your external account is linked to your profile successfully.')); + $this->flash->success(t('Your external account is linked to your profile successfully.')); $this->authentication->backend($backend)->updateUser($this->userSession->getId(), $profile); } diff --git a/app/Controller/Project.php b/app/Controller/Project.php index f30d70e27..2d9c25de2 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -70,9 +70,9 @@ class Project extends Base $this->checkCSRFParam(); if ($this->project->{$switch.'PublicAccess'}($project['id'])) { - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); } else { - $this->session->flashError(t('Unable to update this project.')); + $this->flash->failure(t('Unable to update this project.')); } $this->response->redirect($this->helper->url->to('project', 'share', array('project_id' => $project['id']))); @@ -95,7 +95,7 @@ class Project extends Base if ($this->request->isPost()) { $this->projectMetadata->save($project['id'], $this->request->getValues()); - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); $this->response->redirect($this->helper->url->to('project', 'integrations', array('project_id' => $project['id']))); } @@ -120,7 +120,7 @@ class Project extends Base if ($this->request->isPost()) { $values = $this->request->getValues(); $this->projectNotification->saveSettings($project['id'], $values); - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); $this->response->redirect($this->helper->url->to('project', 'notifications', array('project_id' => $project['id']))); } @@ -173,10 +173,10 @@ class Project extends Base if ($valid) { if ($this->project->update($values)) { - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); $this->response->redirect($this->helper->url->to('project', 'edit', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to update this project.')); + $this->flash->failure(t('Unable to update this project.')); } } @@ -212,9 +212,9 @@ class Project extends Base if ($valid) { if ($this->project->update($values)) { - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); } else { - $this->session->flashError(t('Unable to update this project.')); + $this->flash->failure(t('Unable to update this project.')); } } @@ -233,9 +233,9 @@ class Project extends Base if ($valid) { if ($this->projectPermission->addMember($values['project_id'], $values['user_id'])) { - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); } else { - $this->session->flashError(t('Unable to update this project.')); + $this->flash->failure(t('Unable to update this project.')); } } @@ -261,9 +261,9 @@ class Project extends Base if ($valid) { if ($this->projectPermission->changeRole($values['project_id'], $values['user_id'], $values['is_owner'])) { - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); } else { - $this->session->flashError(t('Unable to update this project.')); + $this->flash->failure(t('Unable to update this project.')); } } @@ -288,9 +288,9 @@ class Project extends Base if ($valid) { if ($this->projectPermission->revokeMember($values['project_id'], $values['user_id'])) { - $this->session->flash(t('Project updated successfully.')); + $this->flash->success(t('Project updated successfully.')); } else { - $this->session->flashError(t('Unable to update this project.')); + $this->flash->failure(t('Unable to update this project.')); } } @@ -310,9 +310,9 @@ class Project extends Base $this->checkCSRFParam(); if ($this->project->remove($project['id'])) { - $this->session->flash(t('Project removed successfully.')); + $this->flash->success(t('Project removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this project.')); + $this->flash->failure(t('Unable to remove this project.')); } $this->response->redirect($this->helper->url->to('project', 'index')); @@ -338,9 +338,9 @@ class Project extends Base if ($this->request->getStringParam('duplicate') === 'yes') { $values = array_keys($this->request->getValues()); if ($this->projectDuplication->duplicate($project['id'], $values) !== false) { - $this->session->flash(t('Project cloned successfully.')); + $this->flash->success(t('Project cloned successfully.')); } else { - $this->session->flashError(t('Unable to clone this project.')); + $this->flash->failure(t('Unable to clone this project.')); } $this->response->redirect($this->helper->url->to('project', 'index')); @@ -365,9 +365,9 @@ class Project extends Base $this->checkCSRFParam(); if ($this->project->disable($project['id'])) { - $this->session->flash(t('Project disabled successfully.')); + $this->flash->success(t('Project disabled successfully.')); } else { - $this->session->flashError(t('Unable to disable this project.')); + $this->flash->failure(t('Unable to disable this project.')); } $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project['id']))); @@ -392,9 +392,9 @@ class Project extends Base $this->checkCSRFParam(); if ($this->project->enable($project['id'])) { - $this->session->flash(t('Project activated successfully.')); + $this->flash->success(t('Project activated successfully.')); } else { - $this->session->flashError(t('Unable to activate this project.')); + $this->flash->failure(t('Unable to activate this project.')); } $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project['id']))); @@ -438,11 +438,11 @@ class Project extends Base $project_id = $this->project->create($values, $this->userSession->getId(), true); if ($project_id > 0) { - $this->session->flash(t('Your project have been created successfully.')); + $this->flash->success(t('Your project have been created successfully.')); $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project_id))); } - $this->session->flashError(t('Unable to create your project.')); + $this->flash->failure(t('Unable to create your project.')); } $this->create($values, $errors); diff --git a/app/Controller/Subtask.php b/app/Controller/Subtask.php index 4ef3e74e6..30ddc375e 100644 --- a/app/Controller/Subtask.php +++ b/app/Controller/Subtask.php @@ -67,9 +67,9 @@ class Subtask extends Base if ($valid) { if ($this->subtask->create($values)) { - $this->session->flash(t('Sub-task added successfully.')); + $this->flash->success(t('Sub-task added successfully.')); } else { - $this->session->flashError(t('Unable to create your sub-task.')); + $this->flash->failure(t('Unable to create your sub-task.')); } if (isset($values['another_subtask']) && $values['another_subtask'] == 1) { @@ -117,9 +117,9 @@ class Subtask extends Base if ($valid) { if ($this->subtask->update($values)) { - $this->session->flash(t('Sub-task updated successfully.')); + $this->flash->success(t('Sub-task updated successfully.')); } else { - $this->session->flashError(t('Unable to update your sub-task.')); + $this->flash->failure(t('Unable to update your sub-task.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks')); @@ -156,9 +156,9 @@ class Subtask extends Base $subtask = $this->getSubtask(); if ($this->subtask->remove($subtask['id'])) { - $this->session->flash(t('Sub-task removed successfully.')); + $this->flash->success(t('Sub-task removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this sub-task.')); + $this->flash->failure(t('Unable to remove this sub-task.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks')); @@ -178,7 +178,7 @@ class Subtask extends Base $this->subtask->toggleStatus($subtask['id']); if ($redirect === 'board') { - $this->session['has_subtask_inprogress'] = $this->subtask->hasSubtaskInProgress($this->userSession->getId()); + $this->sessionStorage->hasSubtaskInProgress = $this->subtask->hasSubtaskInProgress($this->userSession->getId()); $this->response->html($this->template->render('board/tooltip_subtasks', array( 'subtasks' => $this->subtask->getAll($task['id']), diff --git a/app/Controller/Swimlane.php b/app/Controller/Swimlane.php index 0b29f5980..5229621cf 100644 --- a/app/Controller/Swimlane.php +++ b/app/Controller/Swimlane.php @@ -24,7 +24,7 @@ class Swimlane extends Base $swimlane = $this->swimlane->getById($this->request->getIntegerParam('swimlane_id')); if (empty($swimlane)) { - $this->session->flashError(t('Swimlane not found.')); + $this->flash->failure(t('Swimlane not found.')); $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project_id))); } @@ -64,10 +64,10 @@ class Swimlane extends Base if ($valid) { if ($this->swimlane->create($values)) { - $this->session->flash(t('Your swimlane have been created successfully.')); + $this->flash->success(t('Your swimlane have been created successfully.')); $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to create your swimlane.')); + $this->flash->failure(t('Unable to create your swimlane.')); } } @@ -88,10 +88,10 @@ class Swimlane extends Base if ($valid) { if ($this->swimlane->updateDefault($values)) { - $this->session->flash(t('The default swimlane have been updated successfully.')); + $this->flash->success(t('The default swimlane have been updated successfully.')); $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to update this swimlane.')); + $this->flash->failure(t('Unable to update this swimlane.')); } } @@ -130,10 +130,10 @@ class Swimlane extends Base if ($valid) { if ($this->swimlane->update($values)) { - $this->session->flash(t('Swimlane updated successfully.')); + $this->flash->success(t('Swimlane updated successfully.')); $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); } else { - $this->session->flashError(t('Unable to update this swimlane.')); + $this->flash->failure(t('Unable to update this swimlane.')); } } @@ -169,9 +169,9 @@ class Swimlane extends Base $swimlane_id = $this->request->getIntegerParam('swimlane_id'); if ($this->swimlane->remove($project['id'], $swimlane_id)) { - $this->session->flash(t('Swimlane removed successfully.')); + $this->flash->success(t('Swimlane removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this swimlane.')); + $this->flash->failure(t('Unable to remove this swimlane.')); } $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); @@ -189,9 +189,9 @@ class Swimlane extends Base $swimlane_id = $this->request->getIntegerParam('swimlane_id'); if ($this->swimlane->disable($project['id'], $swimlane_id)) { - $this->session->flash(t('Swimlane updated successfully.')); + $this->flash->success(t('Swimlane updated successfully.')); } else { - $this->session->flashError(t('Unable to update this swimlane.')); + $this->flash->failure(t('Unable to update this swimlane.')); } $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); @@ -209,9 +209,9 @@ class Swimlane extends Base $swimlane_id = $this->request->getIntegerParam('swimlane_id'); if ($this->swimlane->enable($project['id'], $swimlane_id)) { - $this->session->flash(t('Swimlane updated successfully.')); + $this->flash->success(t('Swimlane updated successfully.')); } else { - $this->session->flashError(t('Unable to update this swimlane.')); + $this->flash->failure(t('Unable to update this swimlane.')); } $this->response->redirect($this->helper->url->to('swimlane', 'index', array('project_id' => $project['id']))); diff --git a/app/Controller/Task.php b/app/Controller/Task.php index 894802d83..e71b20177 100644 --- a/app/Controller/Task.php +++ b/app/Controller/Task.php @@ -159,9 +159,9 @@ class Task extends Base $this->checkCSRFParam(); if ($this->task->remove($task['id'])) { - $this->session->flash(t('Task removed successfully.')); + $this->flash->success(t('Task removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this task.')); + $this->flash->failure(t('Unable to remove this task.')); } $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); diff --git a/app/Controller/TaskImport.php b/app/Controller/TaskImport.php index 0e9d21690..f09c14ce4 100644 --- a/app/Controller/TaskImport.php +++ b/app/Controller/TaskImport.php @@ -52,9 +52,9 @@ class TaskImport extends Base $csv->read($filename, array($this->taskImport, 'import')); if ($this->taskImport->counter > 0) { - $this->session->flash(t('%d task(s) have been imported successfully.', $this->taskImport->counter)); + $this->flash->success(t('%d task(s) have been imported successfully.', $this->taskImport->counter)); } else { - $this->session->flashError(t('Nothing have been imported!')); + $this->flash->failure(t('Nothing have been imported!')); } $this->response->redirect($this->helper->url->to('taskImport', 'step1', array('project_id' => $project['id']))); diff --git a/app/Controller/Taskcreation.php b/app/Controller/Taskcreation.php index e47cd1b75..cffa9d740 100644 --- a/app/Controller/Taskcreation.php +++ b/app/Controller/Taskcreation.php @@ -59,10 +59,10 @@ class Taskcreation extends Base list($valid, $errors) = $this->taskValidator->validateCreation($values); if ($valid && $this->taskCreation->create($values)) { - $this->session->flash(t('Task created successfully.')); + $this->flash->success(t('Task created successfully.')); $this->afterSave($project, $values); } else { - $this->session->flashError(t('Unable to create your task.')); + $this->flash->failure(t('Unable to create your task.')); } $this->create($values, $errors); diff --git a/app/Controller/Taskduplication.php b/app/Controller/Taskduplication.php index 79f498fc5..9cd684eb3 100644 --- a/app/Controller/Taskduplication.php +++ b/app/Controller/Taskduplication.php @@ -24,10 +24,10 @@ class Taskduplication extends Base $task_id = $this->taskDuplication->duplicate($task['id']); if ($task_id > 0) { - $this->session->flash(t('Task created successfully.')); + $this->flash->success(t('Task created successfully.')); $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task_id))); } else { - $this->session->flashError(t('Unable to create this task.')); + $this->flash->failure(t('Unable to create this task.')); $this->response->redirect($this->helper->url->to('taskduplication', 'duplicate', array('project_id' => $task['project_id'], 'task_id' => $task['id']))); } } @@ -56,11 +56,11 @@ class Taskduplication extends Base $values['column_id'], $values['category_id'], $values['owner_id'])) { - $this->session->flash(t('Task updated successfully.')); + $this->flash->success(t('Task updated successfully.')); $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $values['project_id'], 'task_id' => $task['id']))); } - $this->session->flashError(t('Unable to update your task.')); + $this->flash->failure(t('Unable to update your task.')); } $this->chooseDestination($task, 'task_duplication/move'); @@ -86,12 +86,12 @@ class Taskduplication extends Base ); if ($task_id > 0) { - $this->session->flash(t('Task created successfully.')); + $this->flash->success(t('Task created successfully.')); $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $values['project_id'], 'task_id' => $task_id))); } } - $this->session->flashError(t('Unable to create your task.')); + $this->flash->failure(t('Unable to create your task.')); } $this->chooseDestination($task, 'task_duplication/copy'); diff --git a/app/Controller/Tasklink.php b/app/Controller/Tasklink.php index 587769ee6..068bf16db 100644 --- a/app/Controller/Tasklink.php +++ b/app/Controller/Tasklink.php @@ -73,7 +73,7 @@ class Tasklink extends Base if ($valid) { if ($this->taskLink->create($values['task_id'], $values['opposite_task_id'], $values['link_id'])) { - $this->session->flash(t('Link added successfully.')); + $this->flash->success(t('Link added successfully.')); if ($ajax) { $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); @@ -83,7 +83,7 @@ class Tasklink extends Base } $errors = array('title' => array(t('The exact same link already exists'))); - $this->session->flashError(t('Unable to create your link.')); + $this->flash->failure(t('Unable to create your link.')); } $this->create($values, $errors); @@ -129,11 +129,11 @@ class Tasklink extends Base if ($valid) { if ($this->taskLink->update($values['id'], $values['task_id'], $values['opposite_task_id'], $values['link_id'])) { - $this->session->flash(t('Link updated successfully.')); + $this->flash->success(t('Link updated successfully.')); $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); } - $this->session->flashError(t('Unable to update your link.')); + $this->flash->failure(t('Unable to update your link.')); } $this->edit($values, $errors); @@ -166,9 +166,9 @@ class Tasklink extends Base $task = $this->getTask(); if ($this->taskLink->remove($this->request->getIntegerParam('link_id'))) { - $this->session->flash(t('Link removed successfully.')); + $this->flash->success(t('Link removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this link.')); + $this->flash->failure(t('Unable to remove this link.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); diff --git a/app/Controller/Taskmodification.php b/app/Controller/Taskmodification.php index b1105dcc6..02b09a368 100644 --- a/app/Controller/Taskmodification.php +++ b/app/Controller/Taskmodification.php @@ -35,9 +35,9 @@ class Taskmodification extends Base list($valid, ) = $this->taskValidator->validateTimeModification($values); if ($valid && $this->taskModification->update($values)) { - $this->session->flash(t('Task updated successfully.')); + $this->flash->success(t('Task updated successfully.')); } else { - $this->session->flashError(t('Unable to update your task.')); + $this->flash->failure(t('Unable to update your task.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']))); @@ -60,9 +60,9 @@ class Taskmodification extends Base if ($valid) { if ($this->taskModification->update($values)) { - $this->session->flash(t('Task updated successfully.')); + $this->flash->success(t('Task updated successfully.')); } else { - $this->session->flashError(t('Unable to update your task.')); + $this->flash->failure(t('Unable to update your task.')); } if ($ajax) { @@ -140,7 +140,7 @@ class Taskmodification extends Base list($valid, $errors) = $this->taskValidator->validateModification($values); if ($valid && $this->taskModification->update($values)) { - $this->session->flash(t('Task updated successfully.')); + $this->flash->success(t('Task updated successfully.')); if ($this->request->isAjax()) { $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); @@ -148,7 +148,7 @@ class Taskmodification extends Base $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']))); } } else { - $this->session->flashError(t('Unable to update your task.')); + $this->flash->failure(t('Unable to update your task.')); $this->edit($values, $errors); } } @@ -169,9 +169,9 @@ class Taskmodification extends Base if ($valid) { if ($this->taskModification->update($values)) { - $this->session->flash(t('Task updated successfully.')); + $this->flash->success(t('Task updated successfully.')); } else { - $this->session->flashError(t('Unable to update your task.')); + $this->flash->failure(t('Unable to update your task.')); } $this->response->redirect($this->helper->url->to('task', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']))); diff --git a/app/Controller/Taskstatus.php b/app/Controller/Taskstatus.php index c0421ea7f..b03baebf6 100644 --- a/app/Controller/Taskstatus.php +++ b/app/Controller/Taskstatus.php @@ -40,9 +40,9 @@ class Taskstatus extends Base $this->checkCSRFParam(); if ($this->taskStatus->$method($task['id'])) { - $this->session->flash($success_message); + $this->flash->success($success_message); } else { - $this->session->flashError($failure_message); + $this->flash->failure($failure_message); } if ($this->request->getStringParam('redirect') === 'board') { diff --git a/app/Controller/Twofactor.php b/app/Controller/Twofactor.php index 179241f80..a7368d6b2 100644 --- a/app/Controller/Twofactor.php +++ b/app/Controller/Twofactor.php @@ -72,9 +72,9 @@ class Twofactor extends User } // Allow the user to test or disable the feature - $_SESSION['user']['twofactor_activated'] = false; + $this->userSession->disable2FA(); - $this->session->flash(t('User updated successfully.')); + $this->flash->success(t('User updated successfully.')); $this->response->redirect($this->helper->url->to('twofactor', 'index', array('user_id' => $user['id']))); } @@ -92,9 +92,9 @@ class Twofactor extends User $values = $this->request->getValues(); if (! empty($values['code']) && $otp->checkTotp(Base32::decode($user['twofactor_secret']), $values['code'])) { - $this->session->flash(t('The two factor authentication code is valid.')); + $this->flash->success(t('The two factor authentication code is valid.')); } else { - $this->session->flashError(t('The two factor authentication code is not valid.')); + $this->flash->failure(t('The two factor authentication code is not valid.')); } $this->response->redirect($this->helper->url->to('twofactor', 'index', array('user_id' => $user['id']))); @@ -114,11 +114,11 @@ class Twofactor extends User $values = $this->request->getValues(); if (! empty($values['code']) && $otp->checkTotp(Base32::decode($user['twofactor_secret']), $values['code'])) { - $this->session['2fa_validated'] = true; - $this->session->flash(t('The two factor authentication code is valid.')); + $this->sessionStorage->postAuth['validated'] = true; + $this->flash->success(t('The two factor authentication code is valid.')); $this->response->redirect($this->helper->url->to('app', 'index')); } else { - $this->session->flashError(t('The two factor authentication code is not valid.')); + $this->flash->failure(t('The two factor authentication code is not valid.')); $this->response->redirect($this->helper->url->to('twofactor', 'code')); } } diff --git a/app/Controller/User.php b/app/Controller/User.php index 8526fb571..22622d172 100644 --- a/app/Controller/User.php +++ b/app/Controller/User.php @@ -99,10 +99,10 @@ class User extends Base $this->userNotificationType->saveSelectedTypes($user_id, array(MailNotification::TYPE)); } - $this->session->flash(t('User created successfully.')); + $this->flash->success(t('User created successfully.')); $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user_id))); } else { - $this->session->flashError(t('Unable to create your user.')); + $this->flash->failure(t('Unable to create your user.')); $values['project_id'] = $project_id; } } @@ -201,7 +201,7 @@ class User extends Base if ($this->request->isPost()) { $values = $this->request->getValues(); $this->userNotification->saveSettings($user['id'], $values); - $this->session->flash(t('User updated successfully.')); + $this->flash->success(t('User updated successfully.')); $this->response->redirect($this->helper->url->to('user', 'notifications', array('user_id' => $user['id']))); } @@ -226,7 +226,7 @@ class User extends Base if ($this->request->isPost()) { $values = $this->request->getValues(); $this->userMetadata->save($user['id'], $values); - $this->session->flash(t('User updated successfully.')); + $this->flash->success(t('User updated successfully.')); $this->response->redirect($this->helper->url->to('user', 'integrations', array('user_id' => $user['id']))); } @@ -264,9 +264,9 @@ class User extends Base $this->checkCSRFParam(); if ($this->user->{$switch.'PublicAccess'}($user['id'])) { - $this->session->flash(t('User updated successfully.')); + $this->flash->success(t('User updated successfully.')); } else { - $this->session->flashError(t('Unable to update this user.')); + $this->flash->failure(t('Unable to update this user.')); } $this->response->redirect($this->helper->url->to('user', 'share', array('user_id' => $user['id']))); @@ -295,9 +295,9 @@ class User extends Base if ($valid) { if ($this->user->update($values)) { - $this->session->flash(t('Password modified successfully.')); + $this->flash->success(t('Password modified successfully.')); } else { - $this->session->flashError(t('Unable to change the password.')); + $this->flash->failure(t('Unable to change the password.')); } $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user['id']))); @@ -344,9 +344,9 @@ class User extends Base if ($valid) { if ($this->user->update($values)) { - $this->session->flash(t('User updated successfully.')); + $this->flash->success(t('User updated successfully.')); } else { - $this->session->flashError(t('Unable to update your user.')); + $this->flash->failure(t('Unable to update your user.')); } $this->response->redirect($this->helper->url->to('user', 'show', array('user_id' => $user['id']))); @@ -381,9 +381,9 @@ class User extends Base if ($valid) { if ($this->user->update($values)) { - $this->session->flash(t('User updated successfully.')); + $this->flash->success(t('User updated successfully.')); } else { - $this->session->flashError(t('Unable to update your user.')); + $this->flash->failure(t('Unable to update your user.')); } $this->response->redirect($this->helper->url->to('user', 'authentication', array('user_id' => $user['id']))); @@ -410,9 +410,9 @@ class User extends Base $this->checkCSRFParam(); if ($this->user->remove($user['id'])) { - $this->session->flash(t('User removed successfully.')); + $this->flash->success(t('User removed successfully.')); } else { - $this->session->flashError(t('Unable to remove this user.')); + $this->flash->failure(t('Unable to remove this user.')); } $this->response->redirect($this->helper->url->to('user', 'index')); diff --git a/app/Controller/UserImport.php b/app/Controller/UserImport.php index 32b9a865b..cbc5aa145 100644 --- a/app/Controller/UserImport.php +++ b/app/Controller/UserImport.php @@ -46,9 +46,9 @@ class UserImport extends Base $csv->read($filename, array($this->userImport, 'import')); if ($this->userImport->counter > 0) { - $this->session->flash(t('%d user(s) have been imported successfully.', $this->userImport->counter)); + $this->flash->success(t('%d user(s) have been imported successfully.', $this->userImport->counter)); } else { - $this->session->flashError(t('Nothing have been imported!')); + $this->flash->failure(t('Nothing have been imported!')); } $this->response->redirect($this->helper->url->to('userImport', 'step1')); diff --git a/app/Core/Base.php b/app/Core/Base.php index 11f4e31ba..d3171024f 100644 --- a/app/Core/Base.php +++ b/app/Core/Base.php @@ -10,6 +10,9 @@ use Pimple\Container; * @package core * @author Frederic Guillot * + * @property \Kanboard\Core\Session\SessionManager $sessionManager + * @property \Kanboard\Core\Session\SessionStorage $sessionStorage + * @property \Kanboard\Core\Session\FlashMessage $flash * @property \Kanboard\Core\Helper $helper * @property \Kanboard\Core\Mail\Client $emailClient * @property \Kanboard\Core\Paginator $paginator @@ -17,7 +20,6 @@ use Pimple\Container; * @property \Kanboard\Core\Http\Request $request * @property \Kanboard\Core\Http\Router $router * @property \Kanboard\Core\Http\Response $response - * @property \Kanboard\Core\Session $session * @property \Kanboard\Core\Template $template * @property \Kanboard\Core\OAuth2 $oauth * @property \Kanboard\Core\Lexer $lexer diff --git a/app/Core/Mail/Client.php b/app/Core/Mail/Client.php index 52caef73a..7b4268bd5 100644 --- a/app/Core/Mail/Client.php +++ b/app/Core/Mail/Client.php @@ -51,7 +51,7 @@ class Client extends Base $author = 'Kanboard'; if ($this->userSession->isLogged()) { - $author = e('%s via Kanboard', $this->user->getFullname($this->session['user'])); + $author = e('%s via Kanboard', $this->helper->user->getFullname()); } $this->getTransport(MAIL_TRANSPORT)->sendEmail($email, $name, $subject, $html, $author); diff --git a/app/Core/Security/Token.php b/app/Core/Security/Token.php index 7aca08afb..2bb66ef25 100644 --- a/app/Core/Security/Token.php +++ b/app/Core/Security/Token.php @@ -38,12 +38,12 @@ class Token extends Base */ public function getCSRFToken() { - if (! isset($_SESSION['csrf_tokens'])) { - $_SESSION['csrf_tokens'] = array(); + if (! isset($this->sessionStorage->csrf)) { + $this->sessionStorage->csrf = array(); } $nonce = self::getToken(); - $_SESSION['csrf_tokens'][$nonce] = true; + $this->sessionStorage->csrf[$nonce] = true; return $nonce; } @@ -57,8 +57,8 @@ class Token extends Base */ public function validateCSRFToken($token) { - if (isset($_SESSION['csrf_tokens'][$token])) { - unset($_SESSION['csrf_tokens'][$token]); + if (isset($this->sessionStorage->csrf[$token])) { + unset($this->sessionStorage->csrf[$token]); return true; } diff --git a/app/Core/Session.php b/app/Core/Session.php deleted file mode 100644 index dd1e760e7..000000000 --- a/app/Core/Session.php +++ /dev/null @@ -1,144 +0,0 @@ -setMessage('success', $message); + } + + /** + * Add failure message + * + * @access public + * @param string $message + */ + public function failure($message) + { + $this->setMessage('failure', $message); + } + + /** + * Add new flash message + * + * @access public + * @param string $key + * @param string $message + */ + public function setMessage($key, $message) + { + if (! isset($this->sessionStorage->flash)) { + $this->sessionStorage->flash = array(); + } + + $this->sessionStorage->flash[$key] = $message; + } + + /** + * Get flash message + * + * @access public + * @param string $key + * @return string + */ + public function getMessage($key) + { + $message = ''; + + if (isset($this->sessionStorage->flash[$key])) { + $message = $this->sessionStorage->flash[$key]; + unset($this->sessionStorage->flash[$key]); + } + + return $message; + } +} diff --git a/app/Core/Session/SessionManager.php b/app/Core/Session/SessionManager.php new file mode 100644 index 000000000..6153efeb1 --- /dev/null +++ b/app/Core/Session/SessionManager.php @@ -0,0 +1,102 @@ +configure(); + + if (ini_get('session.auto_start') == 1) { + session_destroy(); + } + + session_name('KB_SID'); + session_start(); + + $this->container['sessionStorage']->setStorage($_SESSION); + } + + /** + * Destroy the session + * + * @access public + */ + public function close() + { + // Destroy the session cookie + $params = session_get_cookie_params(); + + setcookie( + session_name(), + '', + time() - 42000, + $params['path'], + $params['domain'], + $params['secure'], + $params['httponly'] + ); + + session_unset(); + session_destroy(); + } + + /** + * Define session settings + * + * @access private + */ + private function configure() + { + // Session cookie: HttpOnly and secure flags + session_set_cookie_params( + SESSION_DURATION, + $this->helper->url->dir() ?: '/', + null, + Request::isHTTPS(), + true + ); + + // Avoid session id in the URL + ini_set('session.use_only_cookies', '1'); + ini_set('session.use_trans_sid', '0'); + + // Enable strict mode + ini_set('session.use_strict_mode', '1'); + + // Better session hash + ini_set('session.hash_function', 'sha512'); + ini_set('session.hash_bits_per_character', 6); + + // Set an additional entropy + ini_set('session.entropy_file', '/dev/urandom'); + ini_set('session.entropy_length', '256'); + } +} diff --git a/app/Core/Session/SessionStorage.php b/app/Core/Session/SessionStorage.php new file mode 100644 index 000000000..54d803f74 --- /dev/null +++ b/app/Core/Session/SessionStorage.php @@ -0,0 +1,71 @@ +storage =& $storage; + + // Load dynamically existing session variables into object properties + foreach ($storage as $key => $value) { + $this->$key = $value; + } + } + + /** + * Get all session variables + * + * @access public + * @return array + */ + public function getAll() + { + $session = get_object_vars($this); + unset($session['storage']); + + return $session; + } + + /** + * Copy class properties to external storage + * + * @access public + */ + public function __destruct() + { + $this->storage = $this->getAll(); + } +} diff --git a/app/Helper/App.php b/app/Helper/App.php index 19801fa8c..33729f2b1 100644 --- a/app/Helper/App.php +++ b/app/Helper/App.php @@ -62,18 +62,17 @@ class App extends \Kanboard\Core\Base */ public function flashMessage() { - $html = ''; + $success_message = $this->flash->getMessage('success'); + $failure_message = $this->flash->getMessage('failure'); - if (isset($this->session['flash_message'])) { - $html = '