diff --git a/auth/email.py b/auth/email.py index 2f62d041..cde0f03e 100644 --- a/auth/email.py +++ b/auth/email.py @@ -11,7 +11,7 @@ async def send_auth_email(user, token): Follow the link to authorize """ - url = "%s/confirm_email" % BACKEND_URL + url = "%s/confirm-email" % BACKEND_URL to = "%s <%s>" % (user.username, user.email) url_with_token = "%s?token=%s" % (url, token) text = text % url_with_token diff --git a/main.py b/main.py index e3442fde..cf17ff8f 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from auth.authenticate import JWTAuthenticate from auth.oauth import oauth_login, oauth_authorize from base.redis import redis from base.resolvers import resolvers +from resolvers.auth import confirm_email_handler from resolvers.zine import ShoutsCache from services.main import storages_init from services.stat.reacted import ReactedStorage @@ -54,7 +55,7 @@ async def shutdown(): routes = [ Route("/oauth/{provider}", endpoint=oauth_login), Route("/oauth_authorize", endpoint=oauth_authorize), - # Route("/confirm_email", endpoint=), # should be called on client + Route("/confirm-email", endpoint=confirm_email_handler), # should be called on client ] app = Starlette( diff --git a/resolvers/auth.py b/resolvers/auth.py index ead501e6..47468dc5 100644 --- a/resolvers/auth.py +++ b/resolvers/auth.py @@ -38,7 +38,7 @@ async def get_current_user(_, info): @mutation.field("confirmEmail") -async def confirm_email(*_, confirm_token): +async def confirm_email(_, confirm_token): """confirm owning email address""" user_id = None try: @@ -54,7 +54,14 @@ async def confirm_email(*_, confirm_token): raise InvalidToken(e.message) except Exception as e: print(e) # FIXME: debug only - return {"error": "email not confirmed"} + return {"error": "email is not confirmed"} + + +async def confirm_email_handler(request): + token = request.path_params["token"] + request.session["token"] = token + res = confirm_email(None, token) + return res @mutation.field("registerUser")