fix(auth): handle duplicate account creation gracefully
modify add_user_account to return specific status for duplicate accounts update add_account route to display error when account already exists
This commit is contained in:
parent
473fecdcc7
commit
a80f1c8d3c
14
app.py
14
app.py
@ -260,9 +260,10 @@ def add_account() -> Union[Response, str]:
|
||||
username = request.form["username"]
|
||||
password = request.form["password"]
|
||||
stream = request.form["stream"]
|
||||
if add_user_account(
|
||||
result = add_user_account(
|
||||
base_url, session["auth_credentials"], username, password, stream
|
||||
):
|
||||
)
|
||||
if result is True:
|
||||
# Clear cache for user accounts route
|
||||
cache_key = f"view/{session['username']}/accounts"
|
||||
cache.delete(cache_key)
|
||||
@ -275,6 +276,15 @@ def add_account() -> Union[Response, str]:
|
||||
thread = threading.Thread(target=_update_npm_config_in_background)
|
||||
thread.start()
|
||||
return redirect(url_for("user_accounts"))
|
||||
elif result is False:
|
||||
# Account already exists
|
||||
error = "Account already exists for this user"
|
||||
return render_template(
|
||||
"add_account.html",
|
||||
text_input_enabled=app.config.get("TEXT_INPUT_ENABLED"),
|
||||
shared_text=shared_text,
|
||||
error=error
|
||||
)
|
||||
|
||||
return render_template(
|
||||
"add_account.html",
|
||||
|
@ -75,7 +75,14 @@ def add_user_account(
|
||||
response = _make_api_request(
|
||||
"POST", base_url, auth, "addAccount", payload=payload
|
||||
)
|
||||
return response and response.status_code == 200
|
||||
if response and response.status_code == 200:
|
||||
return True
|
||||
elif response and response.status_code == 409:
|
||||
# Account already exists
|
||||
return False
|
||||
else:
|
||||
# Other error
|
||||
return False
|
||||
|
||||
|
||||
def get_stream_names(base_url: str, auth: str) -> List[str]:
|
||||
|
Loading…
x
Reference in New Issue
Block a user