Compare commits

..

5 Commits

Author SHA1 Message Date
0da1d00c3d
Merge pull request 'feature/implement-separate-remember-me' (#15) from feature/implement-separate-remember-me into master
All checks were successful
soko-web/pipeline/head This commit looks good
Reviewed-on: #15
2023-05-02 12:08:16 +02:00
c57d1d40d4
fixup! remove unnecessary "pass by reference" variables from Request
All checks were successful
soko-web/pipeline/pr-master This commit looks good
2023-05-02 12:02:30 +02:00
6a35344210
pass Session object to Request
Some checks failed
soko-web/pipeline/pr-master There was a failure building this commit
2023-05-02 11:47:08 +02:00
9ade08d8bd
session handler should receive table name in the constructor 2023-05-02 10:52:22 +02:00
a982be6645
remove unnecessary "pass by reference" variables from Request 2023-05-02 10:36:04 +02:00
4 changed files with 19 additions and 16 deletions

View File

@ -4,7 +4,7 @@ use SokoWeb\Interfaces\Authentication\IUser;
interface IRequest
{
public function setParsedRouteParams(array &$routeParams): void;
public function setParsedRouteParams(array $routeParams): void;
public function getBase(): string;

View File

@ -17,23 +17,23 @@ class Request implements IRequest
private array $headers;
private Session $session;
private ISession $session;
private ?IUser $user = null;
public function __construct(
string $base,
array &$get,
array &$post,
array $get,
array $post,
array $headers,
array &$session,
ISession $session,
IUserRepository $userRepository)
{
$this->base = $base;
$this->get = &$get;
$this->post = &$post;
$this->get = $get;
$this->post = $post;
$this->headers = $headers;
$this->session = new Session($session);
$this->session = $session;
$userId = $this->session->get('userId');
if ($userId !== null) {
@ -41,9 +41,9 @@ class Request implements IRequest
}
}
public function setParsedRouteParams(array &$routeParams): void
public function setParsedRouteParams(array $routeParams): void
{
$this->routeParams = &$routeParams;
$this->routeParams = $routeParams;
}
public function getBase(): string

View File

@ -11,13 +11,16 @@ class DatabaseSessionHandler implements ISessionHandler
{
private IConnection $dbConnection;
private string $table;
private bool $exists = false;
private bool $written = false;
public function __construct(IConnection $dbConnection)
public function __construct(IConnection $dbConnection, string $table)
{
$this->dbConnection = $dbConnection;
$this->table = $table;
}
public function open($savePath, $sessionName): bool
@ -32,7 +35,7 @@ class DatabaseSessionHandler implements ISessionHandler
public function read($id): string
{
$select = new Select($this->dbConnection, 'sessions');
$select = new Select($this->dbConnection, $this->table);
$select->columns(['data']);
$select->whereId(substr($id, 0, 32));
@ -49,7 +52,7 @@ class DatabaseSessionHandler implements ISessionHandler
public function write($id, $data): bool
{
$modify = new Modify($this->dbConnection, 'sessions');
$modify = new Modify($this->dbConnection, $this->table);
if ($this->exists) {
$modify->setId(substr($id, 0, 32));
@ -68,7 +71,7 @@ class DatabaseSessionHandler implements ISessionHandler
public function destroy($id): bool
{
$modify = new Modify($this->dbConnection, 'sessions');
$modify = new Modify($this->dbConnection, $this->table);
$modify->setId(substr($id, 0, 32));
$modify->delete();
@ -101,7 +104,7 @@ class DatabaseSessionHandler implements ISessionHandler
return true;
}
$modify = new Modify($this->dbConnection, 'sessions');
$modify = new Modify($this->dbConnection, $this->table);
$modify->setId(substr($id, 0, 32));
$modify->set('updated', (new DateTime())->format('Y-m-d H:i:s'));

View File

@ -14,7 +14,7 @@ Container::$routeCollection = new SokoWeb\Routing\RouteCollection();
Container::$routeCollection->get('index', '', [{app}\Controller\HomeController::class, 'getIndex']);
if (isset($_COOKIE['COOKIES_CONSENT'])) {
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler(Container::$dbConnection);
Container::$sessionHandler = new SokoWeb\Session\DatabaseSessionHandler(Container::$dbConnection, 'sessions');
session_set_save_handler(Container::$sessionHandler, true);
session_start([