Skip to content

Commit

Permalink
Do not crash if action is unknown (#1231)
Browse files Browse the repository at this point in the history
  • Loading branch information
cquintana92 authored Aug 12, 2022
1 parent 7eb44a5 commit ba06852
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions app/auth/views/proton.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from flask_limiter.util import get_remote_address
from flask_login import current_user
from requests_oauthlib import OAuth2Session
from typing import Optional

from app.auth.base import auth_bp
from app.auth.views.login_utils import after_login
Expand Down Expand Up @@ -46,15 +47,16 @@ def get_api_key_for_user(user: User) -> str:
return ak.code


def extract_action() -> Action:
def extract_action() -> Optional[Action]:
action = request.args.get("action")
if action is not None:
if action == "link":
return Action.Link
elif action == "login":
return Action.Login
else:
raise Exception(f"Unknown action: {action}")
LOG.w(f"Unknown action received: {action}")
return None
return Action.Login


Expand All @@ -73,6 +75,8 @@ def proton_login():
return redirect(url_for("auth.login"))

action = extract_action()
if action is None:
return redirect(url_for("auth.login"))
if action == Action.Link and not current_user.is_authenticated:
return redirect(url_for("auth.login"))

Expand Down

0 comments on commit ba06852

Please sign in to comment.