fix:
This commit is contained in:
parent
92da8114c3
commit
75a0b5055e
@ -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
|
Loading…
Reference in New Issue
Block a user