Add isExpired
This commit is contained in:
parent
ae41084ea6
commit
a933a015a8
|
@ -70,7 +70,9 @@ class Api {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function login($mglnr = null, $password = null, $groupid = null): self {
|
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;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ use GuzzleHttp\Cookie\SetCookie;
|
||||||
class CacheCookie {
|
class CacheCookie {
|
||||||
|
|
||||||
private $store;
|
private $store;
|
||||||
|
private $createdAt;
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
$this->store = new \GuzzleHttp\Cookie\CookieJar();
|
$this->store = new \GuzzleHttp\Cookie\CookieJar();
|
||||||
|
@ -26,6 +27,11 @@ class CacheCookie {
|
||||||
'cookie' => $this->store->getCookieByName('JSESSIONID')->getValue(),
|
'cookie' => $this->store->getCookieByName('JSESSIONID')->getValue(),
|
||||||
'created_at' => now(),
|
'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->set($mglnr, $cookie['cookie']);
|
||||||
|
$this->createdAt = $cookie['created_at'];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue