requests-transport
This commit is contained in:
parent
120208a621
commit
bbc5dc441d
|
@ -1,20 +1,15 @@
|
|||
import requests
|
||||
|
||||
import httpx
|
||||
from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN
|
||||
|
||||
api_url = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN or 'discours.io')
|
||||
noreply = "discours.io <noreply@%s>" % (MAILGUN_DOMAIN or 'discours.io')
|
||||
lang_subject = {
|
||||
"ru": "Подтверждение почты",
|
||||
"en": "Confirm email"
|
||||
}
|
||||
|
||||
api_url = f"https://api.mailgun.net/v3/{MAILGUN_DOMAIN or 'discours.io'}/messages"
|
||||
noreply = f"discours.io <noreply@{MAILGUN_DOMAIN or 'discours.io'}>"
|
||||
lang_subject = {"ru": "Подтверждение почты", "en": "Confirm email"}
|
||||
|
||||
async def send_auth_email(user, token, lang="ru", template="email_confirmation"):
|
||||
try:
|
||||
to = "%s <%s>" % (user.name, user.email)
|
||||
if lang not in ['ru', 'en']:
|
||||
lang = 'ru'
|
||||
to = f"{user.name} <{user.email}>"
|
||||
if lang not in ["ru", "en"]:
|
||||
lang = "ru"
|
||||
subject = lang_subject.get(lang, lang_subject["en"])
|
||||
template = template + "_" + lang
|
||||
payload = {
|
||||
|
@ -22,16 +17,11 @@ async def send_auth_email(user, token, lang="ru", template="email_confirmation")
|
|||
"to": to,
|
||||
"subject": subject,
|
||||
"template": template,
|
||||
"h:X-Mailgun-Variables": "{ \"token\": \"%s\" }" % token
|
||||
"h:X-Mailgun-Variables": f'{{ "token": "{token}" }}',
|
||||
}
|
||||
print('[auth.email] payload: %r' % payload)
|
||||
# debug
|
||||
# print('http://localhost:3000/?modal=auth&mode=confirm-email&token=%s' % token)
|
||||
response = requests.post(
|
||||
api_url,
|
||||
auth=("api", MAILGUN_API_KEY),
|
||||
data=payload
|
||||
)
|
||||
response.raise_for_status()
|
||||
print(f"[auth.email] payload: {payload}")
|
||||
async with httpx.AsyncClient() as client:
|
||||
response = await client.post(api_url, auth=("api", MAILGUN_API_KEY), data=payload)
|
||||
response.raise_for_status()
|
||||
except Exception as e:
|
||||
print(e)
|
||||
|
|
|
@ -4,7 +4,7 @@ from datetime import timedelta, timezone, datetime
|
|||
from os import environ, path
|
||||
|
||||
from gql import Client, gql
|
||||
from gql.transport.httpx import HTTPXAsyncTransport
|
||||
from gql.transport.requests import RequestsHTTPTransport
|
||||
|
||||
from services.db import local_session
|
||||
from orm import Topic
|
||||
|
@ -46,7 +46,7 @@ token = environ.get("ACKEE_TOKEN", "")
|
|||
def create_client(headers=None, schema=None):
|
||||
return Client(
|
||||
schema=schema,
|
||||
transport=HTTPXAsyncTransport(
|
||||
transport=RequestsHTTPTransport(
|
||||
url="https://ackee.discours.io/api",
|
||||
headers=headers,
|
||||
),
|
||||
|
|
Loading…
Reference in New Issue
Block a user