diff --git a/auth/email.py b/auth/email.py index 17f4b7f7..e5a0b32b 100644 --- a/auth/email.py +++ b/auth/email.py @@ -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 " % (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: diff --git a/settings.py b/settings.py index 79c48403..d20b8fd5 100644 --- a/settings.py +++ b/settings.py @@ -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"