返回提交历史
Modified
gpt4free/forefront/__init__.py
+18
-23
Deleted
gpt4free/forefront/mail.py
+0
-52
Modified
requirements.txt
+1
-0
XFEstudio/gpt4free
forefront: update account creation logic
* update account creation and verification as per latest forefont API * use official Mail TM library pymailtm, instead of maintaining custom API code
afae7125
代码差异
3 个文件
+19
-75
@@ -1,14 +1,14 @@
1
1
from json import loads
2
from re import match
2
from re import findall
3
3
from time import time, sleep
4
4
from typing import Generator, Optional
5
5
from uuid import uuid4
6
6
7
7
from fake_useragent import UserAgent
8
8
from requests import post
9
from pymailtm import MailTm, Message
9
10
from tls_client import Session
10
11
11
from .mail import Mail
12
12
from .typing import ForeFrontResponse
13
13
14
14
@@ -19,11 +19,8 @@ class Account:
19
19
20
20
start = time()
21
21
22
mail_client = Mail(proxies)
23
mail_token = None
24
mail_address = mail_client.get_mail()
25
26
# print(mail_address)
22
mail_client = MailTm().get_account()
23
mail_address = mail_client.address
27
24
28
25
client = Session(client_identifier='chrome110')
29
26
client.proxies = proxies
@@ -33,7 +30,7 @@ class Account:
33
30
}
34
31
35
32
response = client.post(
36
'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.32.6',
33
'https://clerk.forefront.ai/v1/client/sign_ups?_clerk_js_version=4.38.4',
37
34
data={'email_address': mail_address},
38
35
)
39
36
@@ -45,9 +42,10 @@ class Account:
45
42
return 'Failed to create account!'
46
43
47
44
response = client.post(
48
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.32.6',
45
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/prepare_verification?_clerk_js_version=4.38.4',
49
46
data={
50
'strategy': 'email_code',
47
'strategy': 'email_link',
48
'redirect_url': 'https://accounts.forefront.ai/sign-up/verify'
51
49
},
52
50
)
53
51
@@ -59,26 +57,23 @@ class Account:
59
57
60
58
while True:
61
59
sleep(1)
62
for _ in mail_client.fetch_inbox():
63
if logging:
64
print(mail_client.get_message_content(_['id']))
65
mail_token = match(r'(\d){5,6}', mail_client.get_message_content(_['id'])).group(0)
60
new_message: Message = mail_client.wait_for_message()
61
if logging:
62
print(new_message.data['id'])
63
64
verification_url = findall(r'https:\/\/clerk\.forefront\.ai\/v1\/verify\?token=\w.+', new_message.text)[0]
66
65
67
if mail_token:
66
if verification_url:
68
67
break
69
68
70
69
if logging:
71
print(mail_token)
70
print(verification_url)
72
71
73
response = client.post(
74
f'https://clerk.forefront.ai/v1/client/sign_ups/{trace_token}/attempt_verification?_clerk_js_version=4.38.4',
75
data={'code': mail_token, 'strategy': 'email_code'},
76
)
72
response = client.get(verification_url)
77
73
78
if logging:
79
print(response.json())
74
response = client.get('https://clerk.forefront.ai/v1/client?_clerk_js_version=4.38.4')
80
75
81
token = response.json()['client']['sessions'][0]['last_active_token']['jwt']
76
token = response.json()['response']['sessions'][0]['last_active_token']['jwt']
82
77
83
78
with open('accounts.txt', 'a') as f:
84
79
f.write(f'{mail_address}:{token}\n')
@@ -1,52 +0,0 @@
1
from random import choices
2
from string import ascii_letters
3
4
from requests import Session
5
6
7
class Mail:
8
def __init__(self, proxies: dict = None) -> None:
9
self.client = Session()
10
self.client.proxies = proxies
11
self.client.headers = {
12
"host": "api.mail.tm",
13
"connection": "keep-alive",
14
"sec-ch-ua": "\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"",
15
"accept": "application/json, text/plain, */*",
16
"content-type": "application/json",
17
"sec-ch-ua-mobile": "?0",
18
"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",
19
"sec-ch-ua-platform": "\"macOS\"",
20
"origin": "https://mail.tm",
21
"sec-fetch-site": "same-site",
22
"sec-fetch-mode": "cors",
23
"sec-fetch-dest": "empty",
24
"referer": "https://mail.tm/",
25
"accept-encoding": "gzip, deflate, br",
26
"accept-language": "en-GB,en-US;q=0.9,en;q=0.8",
27
}
28
29
def get_mail(self) -> str:
30
token = ''.join(choices(ascii_letters, k=14)).lower()
31
init = self.client.post(
32
"https://api.mail.tm/accounts", json={"address": f"{token}@bugfoo.com", "password": token}
33
)
34
35
if init.status_code == 201:
36
resp = self.client.post("https://api.mail.tm/token", json={**init.json(), "password": token})
37
38
self.client.headers['authorization'] = 'Bearer ' + resp.json()['token']
39
40
return f"{token}@bugfoo.com"
41
42
else:
43
raise Exception("Failed to create email")
44
45
def fetch_inbox(self):
46
return self.client.get(f"https://api.mail.tm/messages").json()["hydra:member"]
47
48
def get_message(self, message_id: str):
49
return self.client.get(f"https://api.mail.tm/messages/{message_id}").json()
50
51
def get_message_content(self, message_id: str):
52
return self.get_message(message_id)["text"]
@@ -11,3 +11,4 @@ fake-useragent
11
11
twocaptcha
12
12
https://github.com/AI-Yash/st-chat/archive/refs/pull/24/head.zip
13
13
pydantic
14
pymailtm