confirm-fix
This commit is contained in:
parent
99a1d5a867
commit
60e353f34d
|
@ -4,26 +4,24 @@ 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
|
||||||
|
subject = "Confirm email"
|
||||||
tmplt = """<html><body>
|
tmplt = """<html><body>
|
||||||
Follow the <a href='%s'>link</a> to authorize
|
Follow the <a href='%s'>link</a> to authorize
|
||||||
</body></html>
|
</body></html>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
baseUrl = "https://new.discours.io"
|
|
||||||
|
|
||||||
|
|
||||||
async def send_auth_email(user, token):
|
async def send_auth_email(user, token):
|
||||||
try:
|
try:
|
||||||
to = "%s <%s>" % (user.username, user.email)
|
to = "%s <%s>" % (user.username, user.email)
|
||||||
url_with_token = "%s/confirm/%s" % (baseUrl, token)
|
url_with_token = "https://newapi.discours.io/confirm/" + token
|
||||||
response = requests.post(
|
response = requests.post(
|
||||||
api_url,
|
api_url,
|
||||||
auth=("api", MAILGUN_API_KEY),
|
auth=("api", MAILGUN_API_KEY),
|
||||||
data={
|
data={
|
||||||
"from": noreply,
|
"from": noreply,
|
||||||
"to": to,
|
"to": to,
|
||||||
"subject": "Confirm email",
|
"subject": subject,
|
||||||
"html": tmplt % url_with_token,
|
"html": tmplt % url_with_token,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
4
main.py
4
main.py
|
@ -13,7 +13,7 @@ from auth.authenticate import JWTAuthenticate
|
||||||
from auth.oauth import oauth_login, oauth_authorize
|
from auth.oauth import oauth_login, oauth_authorize
|
||||||
from base.redis import redis
|
from base.redis import redis
|
||||||
from base.resolvers import resolvers
|
from base.resolvers import resolvers
|
||||||
# from resolvers.auth import confirm_email_handler
|
from resolvers.auth import confirm_email_handler
|
||||||
from resolvers.zine import ShoutsCache
|
from resolvers.zine import ShoutsCache
|
||||||
from services.main import storages_init
|
from services.main import storages_init
|
||||||
from services.stat.reacted import ReactedStorage
|
from services.stat.reacted import ReactedStorage
|
||||||
|
@ -55,7 +55,7 @@ async def shutdown():
|
||||||
routes = [
|
routes = [
|
||||||
Route("/oauth/{provider}", endpoint=oauth_login),
|
Route("/oauth/{provider}", endpoint=oauth_login),
|
||||||
Route("/oauth-authorize", endpoint=oauth_authorize),
|
Route("/oauth-authorize", endpoint=oauth_authorize),
|
||||||
# Route("/confirm-email/{token}", endpoint=confirm_email_handler), # should be called on client
|
Route("/confirm-email/{token}", endpoint=confirm_email_handler), # should be called on client
|
||||||
]
|
]
|
||||||
|
|
||||||
app = Starlette(
|
app = Starlette(
|
||||||
|
|
|
@ -3,6 +3,7 @@ from datetime import datetime
|
||||||
|
|
||||||
from graphql.type import GraphQLResolveInfo
|
from graphql.type import GraphQLResolveInfo
|
||||||
from transliterate import translit
|
from transliterate import translit
|
||||||
|
from starlette.responses import RedirectResponse
|
||||||
|
|
||||||
from auth.tokenstorage import TokenStorage
|
from auth.tokenstorage import TokenStorage
|
||||||
from auth.authenticate import login_required
|
from auth.authenticate import login_required
|
||||||
|
@ -61,6 +62,15 @@ async def confirm_email(_, _info, confirm_token):
|
||||||
return {"error": "email is not confirmed"}
|
return {"error": "email is not confirmed"}
|
||||||
|
|
||||||
|
|
||||||
|
async def confirm_email_handler(request):
|
||||||
|
token = request.path_params["token"] # one time
|
||||||
|
request.session["token"] = token
|
||||||
|
res = await confirm_email(None, token)
|
||||||
|
response = RedirectResponse(url="https://new.discours.io/confirm")
|
||||||
|
response.set_cookie("token", res["token"]) # session token
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def create_user(user_dict):
|
def create_user(user_dict):
|
||||||
user = User(**user_dict)
|
user = User(**user_dict)
|
||||||
user.roles.append(Role.default_role)
|
user.roles.append(Role.default_role)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user