Add possibility to log out (clear session cookie)

This commit is contained in:
Yohann D'ANELLO 2020-10-08 20:59:19 +02:00
parent 14b06560e6
commit 3f46bf74d8
1 changed files with 10 additions and 0 deletions

View File

@ -67,6 +67,7 @@ class Client:
def __init__(self, sympa_url: str): def __init__(self, sympa_url: str):
self.sympa_url = sympa_url self.sympa_url = sympa_url
self.zeep = ZeepClient(sympa_url + "/wsdl", settings=ZeepSettings(strict=False)) self.zeep = ZeepClient(sympa_url + "/wsdl", settings=ZeepSettings(strict=False))
self.cookie = None
def login(self, email: str, password: str) -> None: def login(self, email: str, password: str) -> None:
""" """
@ -79,8 +80,17 @@ class Client:
if self.check_cookie() != email: if self.check_cookie() != email:
# FIXME Better exception # FIXME Better exception
raise Exception("Unknown error: given cookie is invalid") raise Exception("Unknown error: given cookie is invalid")
self.email = email
print("Successfully authenticated!") print("Successfully authenticated!")
def logout(self):
"""
Clear cookie
"""
self.cookie = None
self.email = None
self.zeep.settings.extra_http_headers = []
def check_cookie(self) -> str: def check_cookie(self) -> str:
""" """
From the current cookie, retrieve the email address. From the current cookie, retrieve the email address.