Пофиксил апи сохранения токенов и режим отладки

This commit is contained in:
Ivan
2021-04-28 14:46:28 +03:00
parent 277f1e1aff
commit 5ddadac47c
2 changed files with 14 additions and 3 deletions

View File

@@ -26,9 +26,12 @@ class Application(tk.Tk):
def login(self):
"""Возвращает пользователя - его можно потом сериализовать"""
# Пользователь сохранен! Авторизация не нужна!
try:
user = User.load()
if user is not None:
return user
except Exception as e:
print("Failed to restore login:", e)
# Не удалось - нужен логин
self.frame = LoginFrame(master=self, url=DEFAULT_URL)
while not self.frame.loggedIn:

View File

@@ -161,6 +161,9 @@ class User(UserApi):
"""
Remove the login file from homedir
"""
if "DEBUG" in os.environ:
print("Debug mode is on - no login storing")
return
if not os.path.exists(USER_TOKEN_PATH):
return
try:
@@ -172,6 +175,9 @@ class User(UserApi):
"""
Store user token in homedir
"""
if "DEBUG" in os.environ:
print("Debug mode is on - no login storing")
return
try:
with open(USER_TOKEN_PATH, "w") as handler:
json.dump(self.token.__dict__, handler)
@@ -183,6 +189,8 @@ class User(UserApi):
"""
Restore user token from the file in homedir
"""
if "DEBUG" in os.environ:
raise RuntimeError("Debug mode is on - no login storing")
if os.path.exists(USER_TOKEN_PATH):
try:
with open(USER_TOKEN_PATH, "r") as handler: