From aafba86a94d3e38775e7c7b11a93e242cc444707 Mon Sep 17 00:00:00 2001 From: derrod Date: Fri, 8 Oct 2021 10:36:32 +0200 Subject: [PATCH] [core] Validate session expiry time before skipping login --- legendary/core.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/legendary/core.py b/legendary/core.py index 553e050..a927ff8 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -180,8 +180,16 @@ class LegendaryCore: """ if not self.lgd.userdata: raise ValueError('No saved credentials') - elif self.logged_in: - return True + elif self.logged_in and self.lgd.userdata['expires_at']: + dt_exp = datetime.fromisoformat(self.lgd.userdata['expires_at'][:-1]) + dt_now = datetime.utcnow() + td = dt_now - dt_exp + + # if session still has at least 10 minutes left we can re-use it. + if dt_exp > dt_now and abs(td.total_seconds()) > 600: + return True + else: + self.logged_in = False # run update check if self.update_check_enabled():