i18n email templates
This commit is contained in:
parent
27cb1c0a69
commit
efe60cb0c8
|
@ -5,12 +5,14 @@ from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN
|
||||||
api_url = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN
|
api_url = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN
|
||||||
noreply = "discours.io <noreply@%s>" % MAILGUN_DOMAIN
|
noreply = "discours.io <noreply@%s>" % MAILGUN_DOMAIN
|
||||||
|
|
||||||
async def send_auth_email(user, token):
|
|
||||||
|
async def send_auth_email(user, token, lang="ru"):
|
||||||
try:
|
try:
|
||||||
to = "%s <%s>" % (user.name, user.email)
|
to = "%s <%s>" % (user.name, user.email)
|
||||||
# TODO: i18n
|
|
||||||
subject = "Confirm email"
|
subject = "Confirm email"
|
||||||
template = "email_confirmation_ru"
|
if lang not in ['ru', 'en']:
|
||||||
|
lang = 'ru'
|
||||||
|
template = "email_confirmation_" + lang
|
||||||
|
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
api_url,
|
api_url,
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from urllib.parse import quote_plus
|
from urllib.parse import quote_plus
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
@ -91,7 +93,7 @@ def generate_unique_slug(name):
|
||||||
c += 1
|
c += 1
|
||||||
if not user:
|
if not user:
|
||||||
unique_slug = slug
|
unique_slug = slug
|
||||||
return quote_plus(unique_slug)
|
return quote_plus(unique_slug).replace('+', '-')
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("registerUser")
|
@mutation.field("registerUser")
|
||||||
|
@ -120,7 +122,7 @@ async def register(_, _info, email: str, password: str = "", name: str = ""):
|
||||||
|
|
||||||
|
|
||||||
@mutation.field("sendLink")
|
@mutation.field("sendLink")
|
||||||
async def auth_send_link(_, _info, email):
|
async def auth_send_link(_, _info, email, lang="ru"):
|
||||||
"""send link with confirm code to email"""
|
"""send link with confirm code to email"""
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
user = session.query(User).filter(User.email == email).first()
|
user = session.query(User).filter(User.email == email).first()
|
||||||
|
@ -128,12 +130,12 @@ async def auth_send_link(_, _info, email):
|
||||||
raise ObjectNotExist("User not found")
|
raise ObjectNotExist("User not found")
|
||||||
else:
|
else:
|
||||||
token = await TokenStorage.create_onetime(user)
|
token = await TokenStorage.create_onetime(user)
|
||||||
await send_auth_email(user, token)
|
await send_auth_email(user, token, lang)
|
||||||
return user
|
return user
|
||||||
|
|
||||||
|
|
||||||
@query.field("signIn")
|
@query.field("signIn")
|
||||||
async def login(_, _info, email: str, password: str = ""):
|
async def login(_, _info, email: str, password: str = "", lang: str = "ru"):
|
||||||
|
|
||||||
with local_session() as session:
|
with local_session() as session:
|
||||||
orm_user = session.query(User).filter(User.email == email).first()
|
orm_user = session.query(User).filter(User.email == email).first()
|
||||||
|
@ -145,7 +147,7 @@ async def login(_, _info, email: str, password: str = ""):
|
||||||
if not password:
|
if not password:
|
||||||
print(f"[auth] send confirm link to {email}")
|
print(f"[auth] send confirm link to {email}")
|
||||||
token = await TokenStorage.create_onetime(orm_user)
|
token = await TokenStorage.create_onetime(orm_user)
|
||||||
await send_auth_email(orm_user, token)
|
await send_auth_email(orm_user, token, lang)
|
||||||
# FIXME: not an error, warning
|
# FIXME: not an error, warning
|
||||||
return {"error": "no password, email link was sent"}
|
return {"error": "no password, email link was sent"}
|
||||||
|
|
||||||
|
|
|
@ -155,7 +155,7 @@ type Mutation {
|
||||||
# auth
|
# auth
|
||||||
refreshSession: AuthResult!
|
refreshSession: AuthResult!
|
||||||
registerUser(email: String!, password: String, name: String): AuthResult!
|
registerUser(email: String!, password: String, name: String): AuthResult!
|
||||||
sendLink(email: String!): Result!
|
sendLink(email: String!, lang: String): Result!
|
||||||
confirmEmail(code: String!): AuthResult!
|
confirmEmail(code: String!): AuthResult!
|
||||||
|
|
||||||
# shout
|
# shout
|
||||||
|
@ -212,7 +212,7 @@ type Query {
|
||||||
|
|
||||||
# auth
|
# auth
|
||||||
isEmailUsed(email: String!): Boolean!
|
isEmailUsed(email: String!): Boolean!
|
||||||
signIn(email: String!, password: String): AuthResult!
|
signIn(email: String!, password: String, lang: String): AuthResult!
|
||||||
signOut: AuthResult!
|
signOut: AuthResult!
|
||||||
|
|
||||||
# profile
|
# profile
|
||||||
|
|
Loading…
Reference in New Issue
Block a user