Add isExpired

This commit is contained in:
philipp lang 2021-06-24 22:52:19 +02:00
parent ae41084ea6
commit a933a015a8
2 changed files with 10 additions and 1 deletions

View File

@ -70,7 +70,9 @@ class Api {
}
public function login($mglnr = null, $password = null, $groupid = null): self {
if ($this->cookie->resolve($mglnr)) {
$resolved = $this->cookie->resolve($mglnr);
if ($resolved && !$this->cookie->isExpired()) {
return $this;
}

View File

@ -8,6 +8,7 @@ use GuzzleHttp\Cookie\SetCookie;
class CacheCookie {
private $store;
private $createdAt;
public function __construct() {
$this->store = new \GuzzleHttp\Cookie\CookieJar();
@ -26,6 +27,11 @@ class CacheCookie {
'cookie' => $this->store->getCookieByName('JSESSIONID')->getValue(),
'created_at' => now(),
]);
$this->createdAt = now();
}
public function isExpired() {
return $this->createdAt->addHour(1)->isPast();
}
/**
@ -47,6 +53,7 @@ class CacheCookie {
}
$this->set($mglnr, $cookie['cookie']);
$this->createdAt = $cookie['created_at'];
return true;
}