Skip to content

Commit

Permalink
[core] Validate session expiry time before skipping login
Browse files Browse the repository at this point in the history
  • Loading branch information
derrod committed Oct 8, 2021
1 parent 5d4beeb commit aafba86
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions legendary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,16 @@ def login(self) -> bool:
"""
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():
Expand Down

0 comments on commit aafba86

Please sign in to comment.