From a933a015a855080da47a785c6ead486ea54b4eac Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 24 Jun 2021 22:52:19 +0200 Subject: [PATCH] Add isExpired --- src/Api.php | 4 +++- src/Cookies/CacheCookie.php | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Api.php b/src/Api.php index ce60bda..3353d2e 100644 --- a/src/Api.php +++ b/src/Api.php @@ -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; } diff --git a/src/Cookies/CacheCookie.php b/src/Cookies/CacheCookie.php index 38518da..a93be11 100644 --- a/src/Cookies/CacheCookie.php +++ b/src/Cookies/CacheCookie.php @@ -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; }