Replace the single user (defined in /data/config.php) with a multi user management thing

This commit is contained in:
Bernd Bestel
2018-07-24 19:31:43 +02:00
parent b52ab91606
commit 7f8540ff4e
19 changed files with 695 additions and 23 deletions

View File

@@ -33,11 +33,12 @@ class SessionService extends BaseService
/**
* @return string
*/
public function CreateSession()
public function CreateSession($userId)
{
$newSessionKey = $this->GenerateSessionKey();
$sessionRow = $this->Database->sessions()->createRow(array(
'user_id' => $userId,
'session_key' => $newSessionKey,
'expires' => date('Y-m-d H:i:s', time() + 2592000) // Default is that sessions expire in 30 days
));
@@ -51,6 +52,16 @@ class SessionService extends BaseService
$this->Database->sessions()->where('session_key', $sessionKey)->delete();
}
public function GetUserBySessionKey($sessionKey)
{
$sessionRow = $this->Database->sessions()->where('session_key', $sessionKey)->fetch();
if ($sessionRow !== null)
{
return $this->Database->users($sessionRow->user_id);
}
return null;
}
private function GenerateSessionKey()
{
return RandomString(50);