diff --git a/auth/email.py b/auth/email.py index ca369aa8..5a7ae3ca 100644 --- a/auth/email.py +++ b/auth/email.py @@ -5,12 +5,14 @@ from settings import MAILGUN_API_KEY, MAILGUN_DOMAIN api_url = "https://api.mailgun.net/v3/%s/messages" % MAILGUN_DOMAIN noreply = "discours.io " % MAILGUN_DOMAIN -async def send_auth_email(user, token): + +async def send_auth_email(user, token, lang="ru"): try: to = "%s <%s>" % (user.name, user.email) - # TODO: i18n subject = "Confirm email" - template = "email_confirmation_ru" + if lang not in ['ru', 'en']: + lang = 'ru' + template = "email_confirmation_" + lang response = requests.post( api_url, diff --git a/resolvers/auth.py b/resolvers/auth.py index 3f4e8f32..b98c469a 100644 --- a/resolvers/auth.py +++ b/resolvers/auth.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from urllib.parse import quote_plus from datetime import datetime @@ -91,7 +93,7 @@ def generate_unique_slug(name): c += 1 if not user: unique_slug = slug - return quote_plus(unique_slug) + return quote_plus(unique_slug).replace('+', '-') @mutation.field("registerUser") @@ -120,7 +122,7 @@ async def register(_, _info, email: str, password: str = "", name: str = ""): @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""" with local_session() as session: 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") else: token = await TokenStorage.create_onetime(user) - await send_auth_email(user, token) + await send_auth_email(user, token, lang) return user @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: 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: print(f"[auth] send confirm link to {email}") 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 return {"error": "no password, email link was sent"} diff --git a/schema.graphql b/schema.graphql index a3b47bf8..62800219 100644 --- a/schema.graphql +++ b/schema.graphql @@ -155,7 +155,7 @@ type Mutation { # auth refreshSession: AuthResult! registerUser(email: String!, password: String, name: String): AuthResult! - sendLink(email: String!): Result! + sendLink(email: String!, lang: String): Result! confirmEmail(code: String!): AuthResult! # shout @@ -212,7 +212,7 @@ type Query { # auth isEmailUsed(email: String!): Boolean! - signIn(email: String!, password: String): AuthResult! + signIn(email: String!, password: String, lang: String): AuthResult! signOut: AuthResult! # profile