redirect to ERROR_URL_ON_FRONTEND on email auth error
This commit is contained in:
parent
f93b17cead
commit
bb96dc00a6
|
@ -4,7 +4,8 @@ from starlette.exceptions import HTTPException
|
|||
|
||||
from auth.authenticate import EmailAuthenticate, ResetPassword
|
||||
|
||||
from settings import BACKEND_URL, MAILGUN_API_KEY, MAILGUN_DOMAIN, RESET_PWD_URL, CONFIRM_EMAIL_URL
|
||||
from settings import BACKEND_URL, MAILGUN_API_KEY, MAILGUN_DOMAIN, RESET_PWD_URL, \
|
||||
CONFIRM_EMAIL_URL, ERROR_URL_ON_FRONTEND
|
||||
|
||||
MAILGUN_API_URL = "https://api.mailgun.net/v3/%s/messages" % (MAILGUN_DOMAIN)
|
||||
MAILGUN_FROM = "postmaster <postmaster@%s>" % (MAILGUN_DOMAIN)
|
||||
|
@ -45,9 +46,14 @@ async def send_email(user, url, text, token):
|
|||
async def email_authorize(request):
|
||||
token = request.query_params.get('token')
|
||||
if not token:
|
||||
raise HTTPException(500, "invalid url")
|
||||
url_with_error = "%s?error=%s" % (ERROR_URL_ON_FRONTEND, "INVALID_TOKEN")
|
||||
return RedirectResponse(url = url_with_error)
|
||||
|
||||
auth_token, user = await EmailAuthenticate.authenticate(token)
|
||||
try:
|
||||
auth_token, user = await EmailAuthenticate.authenticate(token)
|
||||
except:
|
||||
url_with_error = "%s?error=%s" % (ERROR_URL_ON_FRONTEND, "INVALID_TOKEN")
|
||||
return RedirectResponse(url = url_with_error)
|
||||
|
||||
if not user.emailConfirmed:
|
||||
with local_session() as session:
|
||||
|
|
|
@ -8,6 +8,7 @@ BACKEND_URL = environ.get("BACKEND_URL") or "https://localhost:8080"
|
|||
OAUTH_CALLBACK_URL = environ.get("OAUTH_CALLBACK_URL") or "https://localhost:8080"
|
||||
RESET_PWD_URL = environ.get("RESET_PWD_URL") or "https://localhost:8080/reset_pwd"
|
||||
CONFIRM_EMAIL_URL = environ.get("CONFIRM_EMAIL_URL") or "https://new.discours.io"
|
||||
ERROR_URL_ON_FRONTEND = environ.get("ERROR_URL_ON_FRONTEND") or "https://new.discours.io"
|
||||
|
||||
DB_URL = environ.get("DATABASE_URL") or environ.get("DB_URL") or "sqlite:///db.sqlite3"
|
||||
JWT_ALGORITHM = "HS256"
|
||||
|
|
Loading…
Reference in New Issue
Block a user