feature/implement-separate-remember-me #15
@ -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'));
 | 
			
		||||
 | 
			
		||||
@ -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([
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user