Files
grocy/services/SessionService.php

43 lines
815 B
PHP
Raw Normal View History

2018-04-10 20:30:11 +02:00
<?php
2018-04-11 19:49:35 +02:00
namespace Grocy\Services;
class SessionService extends BaseService
2018-04-10 20:30:11 +02:00
{
/**
* @return boolean
*/
2018-04-11 19:49:35 +02:00
public function IsValidSession($sessionKey)
2018-04-10 20:30:11 +02:00
{
if ($sessionKey === null || empty($sessionKey))
{
return false;
}
else
{
2018-04-14 11:10:38 +02:00
return $this->Database->sessions()->where('session_key = :1 AND expires > :2', $sessionKey, time())->count() === 1;
2018-04-10 20:30:11 +02:00
}
}
/**
* @return string
*/
2018-04-11 19:49:35 +02:00
public function CreateSession()
2018-04-10 20:30:11 +02:00
{
$newSessionKey = uniqid() . uniqid() . uniqid();
2018-04-14 11:10:38 +02:00
$sessionRow = $this->Database->sessions()->createRow(array(
'session_key' => $newSessionKey,
'expires' => time() + 2592000 //30 days
));
$sessionRow->save();
2018-04-10 20:30:11 +02:00
return $newSessionKey;
}
2018-04-11 19:49:35 +02:00
public function RemoveSession($sessionKey)
2018-04-10 20:30:11 +02:00
{
2018-04-14 11:10:38 +02:00
$this->Database->sessions()->where('session_key', $sessionKey)->delete();
2018-04-10 20:30:11 +02:00
}
}