mirror of
https://github.com/Noettore/lagomareGateKeeperBot.git
synced 2025-10-15 03:26:40 +02:00
Add token validation
This commit is contained in:
@@ -7,23 +7,41 @@ class AVConnectAPI:
|
||||
|
||||
def __init__(self, credentials: Credential):
|
||||
self._ua = UserAgent(browsers=["Chrome Mobile"], os=["Android"], platforms=["mobile"]).random
|
||||
self._username = credentials.username
|
||||
self._password = credentials.password
|
||||
self._credentials = credentials
|
||||
self._session = requests.Session()
|
||||
self._authenticated = False
|
||||
|
||||
if credentials.sessionid:
|
||||
self._session.cookies.set("PHPSESSID", credentials.sessionid)
|
||||
self._authenticated = True
|
||||
|
||||
def _authenticate(self) -> bool:
|
||||
login_url = f"{self._BASE_URL}/loginone.php"
|
||||
headers = {"Content-Type": "application/x-www-form-urlencoded"}
|
||||
payload = f"userid={self._username}&password={self._password}&entra=Login"
|
||||
headers = {
|
||||
"User-Agent": self._ua,
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
}
|
||||
payload = f"userid={self._credentials.username}&password={self._credentials.password}&entra=Login"
|
||||
response = self._session.post(login_url, data=payload, headers=headers)
|
||||
if response.ok and "PHPSESSID" in self._session.cookies:
|
||||
self._authenticated = True
|
||||
print("Authenticated")
|
||||
return True
|
||||
return False
|
||||
|
||||
def _check_sessionid(self) -> bool:
|
||||
if not self._authenticated or not self._credentials.sessionid:
|
||||
return False
|
||||
exec_url = f"{self._BASE_URL}/exemacrocom.php"
|
||||
headers = {
|
||||
"User-Agent": self._ua,
|
||||
}
|
||||
response = self._session.get(exec_url, headers=headers)
|
||||
print(response.ok)
|
||||
return response.ok
|
||||
|
||||
def exec_gate_macro(self, id_macro) -> bool:
|
||||
if not self._authenticated and not self._authenticate():
|
||||
if (not self._authenticated or not self._check_sessionid()) and not self._authenticate():
|
||||
raise Exception("Authentication failed.")
|
||||
exec_url = f"{self._BASE_URL}/exemacrocom.php"
|
||||
headers = {
|
||||
|
Reference in New Issue
Block a user