From 75a0b5055ec0cca0903cf4fc22819d32204b53bc Mon Sep 17 00:00:00 2001 From: starnakin Date: Fri, 3 Nov 2023 21:05:41 +0100 Subject: [PATCH] fix: --- src/Client.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Client.py b/src/Client.py index 2688e96..93adeeb 100644 --- a/src/Client.py +++ b/src/Client.py @@ -1,6 +1,5 @@ import requests -from requets.Session import Session -from requests import Response, Requests +from requests import Response, Request, Session import urls @@ -9,22 +8,23 @@ class Client: self.url: str = url self.token: str = None self.session: Session = Session() - response: Response = s.get(self.url) - self.csrf_token = response.cookies['csrftoken'] - def is_authentificate(self: Client): + def is_authentificate(self): return (not self.token is None) - def login(self: Client, username: str, password: str): + def login(self, username: str, password: str): response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password}) return response.content - def register(self: Client, username: str, password: str): - response: Response = self._post(urls.accounts_login_url, {'username': username, 'password': password}) - return response.content + def register(self, username: str, password: str): + response: Response = self._post(urls.accounts_register_url, {'username': username, 'password': password}) + return response - def _post(self: Client, uri: str, data: dict): + def _post(self, uri: str, data: dict): url: str = self.url + uri - data.update({'csrfmiddlewaretoken': self.csrf_token}) - response: Response = s.post(url, data = data, headers = dict(Referer=url)) + if self.token is None: + response: Response = self.session.get(url) + self.token = response.cookies['csrftoken'] + data.update({'csrfmiddlewaretoken': self.token}) + response: Response = self.session.post(url, data = data, headers = dict(Referer=url)) return response.content \ No newline at end of file