Merge pull request #285 from Akash98Sky/main

forefront: update account creation logic
This commit is contained in:
t.me/xtekky 2023-04-30 12:20:15 +01:00 committed by GitHub
commit ed196d8aba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 75 deletions

View File

@ -1,14 +1,14 @@
from json import loads from json import loads
from re import match from re import findall
from time import time, sleep from time import time, sleep
from typing import Generator, Optional from typing import Generator, Optional
from uuid import uuid4 from uuid import uuid4
from fake_useragent import UserAgent from fake_useragent import UserAgent
from requests import post from requests import post
from pymailtm import MailTm, Message
from tls_client import Session from tls_client import Session
from .mail import Mail
from .typing import ForeFrontResponse from .typing import ForeFrontResponse
@ -19,11 +19,8 @@ class Account:
start = time() start = time()
mail_client = Mail(proxies) mail_client = MailTm().get_account()
mail_token = None mail_address = mail_client.address
mail_address = mail_client.get_mail()
# print(mail_address)
client = Session(client_identifier='chrome110') client = Session(client_identifier='chrome110')
client.proxies = proxies client.proxies = proxies
@ -33,7 +30,7 @@ class Account:
} }
response = client.post( response = client.post(
'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6', 'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.38.4',
data={'email_address': mail_address}, data={'email_address': mail_address},
) )
@ -45,9 +42,10 @@ class Account:
return 'Failed to create account!' return 'Failed to create account!'
response = client.post( response = client.post(
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6', f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
data={ data={
'strategy': 'email_code', 'strategy': 'email_link',
'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'
}, },
) )
@ -59,26 +57,23 @@ class Account:
while True: while True:
sleep(1) sleep(1)
for _ in mail_client.fetch_inbox(): new_message: Message = mail_client.wait_for_message()
if logging: if logging:
print(mail_client.get_message_content(_['id'])) print(new_message.data['id'])
mail_token = match(r'(\d){5,6}', mail_client.get_message_content(_['id'])).group(0)
if mail_token: verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', new_message.text)[0]
if verification_url:
break break
if logging: if logging:
print(mail_token) print(verification_url)
response = client.post( response = client.get(verification_url)
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/attempt_verification?_clerk_js_version=4.38.4',
data={'code': mail_token, 'strategy': 'email_code'},
)
if logging: response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')
print(response.json())
token = response.json()['client']['sessions'][0]['last_active_token']['jwt'] token = response.json()['response']['sessions'][0]['last_active_token']['jwt']
with open('accounts.txt', 'a') as f: with open('accounts.txt', 'a') as f:
f.write(f'{mail_address}:{token}\n') f.write(f'{mail_address}:{token}\n')

View File

@ -1,52 +0,0 @@
from random import choices
from string import ascii_letters
from requests import Session
class Mail:
def __init__(self, proxies: dict = None) -> None:
self.client = Session()
self.client.proxies = proxies
self.client.headers = {
"host": "api.mail.tm",
"connection": "keep-alive",
"sec-ch-ua": "\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
"accept": "application/json, text/plain, */*",
"content-type": "application/json",
"sec-ch-ua-mobile": "?0",
"user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36",
"sec-ch-ua-platform": "\"macOS\"",
"origin": "https://mail.tm",
"sec-fetch-site": "same-site",
"sec-fetch-mode": "cors",
"sec-fetch-dest": "empty",
"referer": "https://mail.tm/",
"accept-encoding": "gzip, deflate, br",
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
}
def get_mail(self) -> str:
token = ''.join(choices(ascii_letters, k=14)).lower()
init = self.client.post(
"https://api.mail.tm/accounts", json={"address": f"{token}@bugfoo.com", "password": token}
)
if init.status_code == 201:
resp = self.client.post("https://api.mail.tm/token", json={**init.json(), "password": token})
self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
return f"{token}@bugfoo.com"
else:
raise Exception("Failed to create email")
def fetch_inbox(self):
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]
def get_message(self, message_id: str):
return self.client.get(f"https://api.mail.tm/messages/{message_id}").json()
def get_message_content(self, message_id: str):
return self.get_message(message_id)["text"]

View File

@ -11,3 +11,4 @@ fake-useragent
twocaptcha twocaptcha
https://github.com/AI-Yash/st-chat/archive/refs/pull/24/head.zip https://github.com/AI-Yash/st-chat/archive/refs/pull/24/head.zip
pydantic pydantic
pymailtm