Compare commits

..

4 Commits

Author SHA1 Message Date
184f63585c
Merge pull request 'feature/session-handler-changes' (!63) from feature/session-handler-changes into develop
All checks were successful
mapguesser/pipeline/head This commit looks good
Reviewed-on: #63
2023-05-02 13:20:07 +02:00
d666593fde
session should be valid for a session
All checks were successful
mapguesser/pipeline/pr-develop This commit looks good
2023-05-02 13:18:37 +02:00
75fad05362
adapt to new soko-web interfaces 2023-05-02 13:18:14 +02:00
45b34cb514
update to soko-web 0.10 2023-05-02 13:18:03 +02:00
3 changed files with 13 additions and 18 deletions

View File

@ -10,7 +10,7 @@
} }
], ],
"require": { "require": {
"esoko/soko-web": "0.7", "esoko/soko-web": "0.10",
"fzaninotto/faker": "^1.9" "fzaninotto/faker": "^1.9"
}, },
"require-dev": { "require-dev": {

8
composer.lock generated
View File

@ -4,15 +4,15 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "cadf44c9030f1d63cb602a2ddb77db7e", "content-hash": "db04b12ad70bbdfe83841fa292277ec6",
"packages": [ "packages": [
{ {
"name": "esoko/soko-web", "name": "esoko/soko-web",
"version": "v0.7", "version": "0.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://git.esoko.eu/esoko/soko-web.git", "url": "https://git.esoko.eu/esoko/soko-web.git",
"reference": "88a2a99527b51dfb240ec78ac7070dc36a1022b6" "reference": "fd286c9cffadc4a26609bfa00944f8014a2f3f59"
}, },
"require": { "require": {
"phpmailer/phpmailer": "^6.8", "phpmailer/phpmailer": "^6.8",
@ -33,7 +33,7 @@
"GNU GPL 3.0" "GNU GPL 3.0"
], ],
"description": "Lightweight web framework", "description": "Lightweight web framework",
"time": "2023-04-30T18:20:27+00:00" "time": "2023-05-02T10:55:47+00:00"
}, },
{ {
"name": "fzaninotto/faker", "name": "fzaninotto/faker",

21
web.php
View File

@ -4,6 +4,7 @@ use SokoWeb\Response\HttpResponse;
use SokoWeb\Routing\RouteCollection; use SokoWeb\Routing\RouteCollection;
use SokoWeb\Session\DatabaseSessionHandler; use SokoWeb\Session\DatabaseSessionHandler;
use SokoWeb\Request\Request; use SokoWeb\Request\Request;
use SokoWeb\Request\Session;
use MapGuesser\Controller\MapsController; use MapGuesser\Controller\MapsController;
use MapGuesser\Controller\HomeController; use MapGuesser\Controller\HomeController;
use MapGuesser\Controller\LoginController; use MapGuesser\Controller\LoginController;
@ -90,27 +91,21 @@ Container::$routeCollection->group('admin', function (RouteCollection $routeColl
}); });
if (isset($_COOKIE['COOKIES_CONSENT'])) { if (isset($_COOKIE['COOKIES_CONSENT'])) {
Container::$sessionHandler = new DatabaseSessionHandler(Container::$dbConnection); Container::$sessionHandler = new DatabaseSessionHandler(
Container::$dbConnection,
'sessions',
new DateTime('-7 days')
);
session_set_save_handler(Container::$sessionHandler, true); session_set_save_handler(Container::$sessionHandler, true);
session_start([ session_start([
'gc_probability' => 0, // old sessions are deleted by MaintainDatabaseCommand 'gc_probability' => 0, // old sessions are deleted by MaintainDatabaseCommand
'cookie_lifetime' => 604800, 'cookie_lifetime' => 0,
'cookie_path' => '/', 'cookie_path' => '/',
'cookie_httponly' => true, 'cookie_httponly' => true,
'cookie_samesite' => 'Lax' 'cookie_samesite' => 'Lax'
]); ]);
if (isset($_COOKIE[session_name()])) {
// extend session cookie lifetime is cookie already exists
setcookie(session_name(), session_id(), [
'expires' => time() + 604800,
'path' => '/',
'httponly' => true,
'samesite' => 'Lax'
]);
}
// this is needed to handle old type of session IDs // this is needed to handle old type of session IDs
if (!Container::$sessionHandler->validateId(session_id())) { if (!Container::$sessionHandler->validateId(session_id())) {
session_regenerate_id(true); session_regenerate_id(true);
@ -124,7 +119,7 @@ Container::$request = new Request(
$_GET, $_GET,
$_POST, $_POST,
getallheaders(), getallheaders(),
$_SESSION, new Session($_SESSION),
new UserRepository() new UserRepository()
); );