rollback-requests

This commit is contained in:
Tony Rewin 2023-10-06 00:10:46 +03:00
parent 8524d0f843
commit 120208a621
2 changed files with 22 additions and 15 deletions

View File

@ -1,16 +1,20 @@
import httpx import requests
from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN
api_url = f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN or 'discours.io'}/messages" api_url = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN or 'discours.io')
noreply = f"discours.io <noreply@{MAILGUN_DOMAIN or 'discours.io'}>" noreply = "discours.io <noreply@%s>" % (MAILGUN_DOMAIN or 'discours.io')
lang_subject = {"ru": "Подтверждение почты", "en": "Confirm email"} lang_subject = {
"ru": "Подтверждение почты",
"en": "Confirm email"
}
async def send_auth_email(user, token, lang="ru", template="email_confirmation"): async def send_auth_email(user, token, lang="ru", template="email_confirmation"):
try: try:
to = f"{user.name} <{user.email}>" to = "%s <%s>" % (user.name, user.email)
if lang not in ["ru", "en"]: if lang not in ['ru', 'en']:
lang = "ru" lang = 'ru'
subject = lang_subject.get(lang, lang_subject["en"]) subject = lang_subject.get(lang, lang_subject["en"])
template = template + "_" + lang template = template + "_" + lang
payload = { payload = {
@ -18,13 +22,16 @@ async def send_auth_email(user, token, lang="ru", template="email_confirmation")
"to": to, "to": to,
"subject": subject, "subject": subject,
"template": template, "template": template,
"h:X-Mailgun-Variables": f'{{ "token": "{token}" }}', "h:X-Mailgun-Variables": "{ \"token\": \"%s\" }" % token
} }
print(f"[auth.email] payload: {payload}") print('[auth.email] payload: %r' % payload)
async with httpx.AsyncClient() as client: # debug
response = await client.post( # print('http://localhost:3000/?modal=auth&mode=confirm-email&token=%s' % token)
api_url, auth=("api", MAILGUN_API_KEY), data=payload response = requests.post(
) api_url,
response.raise_for_status() auth=("api", MAILGUN_API_KEY),
data=payload
)
response.raise_for_status()
except Exception as e: except Exception as e:
print(e) print(e)

View File

@ -1,6 +1,6 @@
aredis>=1.1.8 aredis>=1.1.8
httpx>=0.23.0 httpx>=0.23.0
git+https://github.com/graphql-python/gql#master gql[requests] # TODO: replace with httpx when stable
git+https://github.com/encode/starlette.git#main git+https://github.com/encode/starlette.git#main
sqlalchemy>=1.4.41 sqlalchemy>=1.4.41
ariadne>=0.17.0 ariadne>=0.17.0