Second part of today's bread.
This commit is contained in:
parent
09a1eeca77
commit
743623201c
1 changed files with 10 additions and 4 deletions
|
@ -18,7 +18,6 @@ class Session
|
||||||
// Initialise new session
|
// Initialise new session
|
||||||
public function __construct($userId, $sessionId = null)
|
public function __construct($userId, $sessionId = null)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Set the supposed session data
|
// Set the supposed session data
|
||||||
$this->userId = $userId;
|
$this->userId = $userId;
|
||||||
$this->sessionId = $sessionId;
|
$this->sessionId = $sessionId;
|
||||||
|
@ -32,7 +31,6 @@ class Session
|
||||||
// Destroy this session
|
// Destroy this session
|
||||||
public function destroy()
|
public function destroy()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Invalidate the session key
|
// Invalidate the session key
|
||||||
Database::delete('sessions', [
|
Database::delete('sessions', [
|
||||||
'session_key' => [$this->sessionId, '='],
|
'session_key' => [$this->sessionId, '='],
|
||||||
|
@ -49,10 +47,19 @@ class Session
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Destroy all sessions keys for this user
|
||||||
|
public function destroyAll()
|
||||||
|
{
|
||||||
|
// Delete all database entries with this user in it
|
||||||
|
Database::delete('sessions', ['user_id' => [$this->userId, '=']]);
|
||||||
|
|
||||||
|
// Destroy this session to finish it off
|
||||||
|
$this->destroy();
|
||||||
|
}
|
||||||
|
|
||||||
// Create a new session
|
// Create a new session
|
||||||
public function create($permanent)
|
public function create($permanent)
|
||||||
{
|
{
|
||||||
|
|
||||||
// Generate session key
|
// Generate session key
|
||||||
$session = hash('sha256', $this->userId . base64_encode('sakura' . mt_rand(0, 99999999)) . time());
|
$session = hash('sha256', $this->userId . base64_encode('sakura' . mt_rand(0, 99999999)) . time());
|
||||||
|
|
||||||
|
@ -74,7 +81,6 @@ class Session
|
||||||
// Validate an apparently existing session
|
// Validate an apparently existing session
|
||||||
public function validate()
|
public function validate()
|
||||||
{
|
{
|
||||||
|
|
||||||
// Get session from database
|
// Get session from database
|
||||||
$session = Database::fetch('sessions', false, [
|
$session = Database::fetch('sessions', false, [
|
||||||
'user_id' => [$this->userId, '='],
|
'user_id' => [$this->userId, '='],
|
||||||
|
|
Reference in a new issue