Compare commits
3 Commits
e46a8862ad
...
b1ada983ec
Author | SHA1 | Date | |
---|---|---|---|
b1ada983ec | |||
4fa0cb083f | |||
f345241ab8 |
15
app.py
15
app.py
@ -135,17 +135,21 @@ def urls():
|
||||
|
||||
|
||||
@app.route("/accounts", methods=["GET"])
|
||||
@cache.cached(timeout=120) # cache for 120 seconds
|
||||
def user_accounts():
|
||||
# Check if the user is logged in
|
||||
if not session.get("logged_in"):
|
||||
return redirect(url_for("home"))
|
||||
# Placeholder content for Accounts page
|
||||
base_url = app.config["BASE_URL"] # Access base_url from the config
|
||||
user_accounts_data = get_user_accounts(base_url, session["auth_credentials"])
|
||||
|
||||
# Clear the cache for 'user_accounts' view specifically
|
||||
cache.delete_memoized(user_accounts)
|
||||
|
||||
return render_template(
|
||||
"user_accounts.html",
|
||||
username=session["username"],
|
||||
user_accounts=get_user_accounts(base_url, session["auth_credentials"]),
|
||||
user_accounts=user_accounts_data,
|
||||
auth=session["auth_credentials"],
|
||||
)
|
||||
|
||||
@ -161,9 +165,9 @@ def add_account():
|
||||
if add_user_account(
|
||||
base_url, session["auth_credentials"], username, password, stream
|
||||
):
|
||||
cache.clear() # Clears all cache entries
|
||||
cache.clear()
|
||||
return redirect(url_for("user_accounts"))
|
||||
return render_template("add_account.html")
|
||||
return render_template("add_account.html", ocr_enabled=app.config.get("OCR_ENABLED"), text_input_enabled=app.config.get("TEXT_INPUT_ENABLED"))
|
||||
|
||||
return render_template("add_account.html", ocr_enabled=app.config.get("OCR_ENABLED"), text_input_enabled=app.config.get("TEXT_INPUT_ENABLED"))
|
||||
|
||||
@ -175,7 +179,6 @@ def delete_account():
|
||||
base_url = app.config["BASE_URL"]
|
||||
|
||||
if delete_user_account(base_url, session["auth_credentials"], stream, username):
|
||||
cache.clear() # Clears all cache entries
|
||||
return redirect(url_for("user_accounts"))
|
||||
return redirect(url_for("user_accounts"))
|
||||
|
||||
@ -204,7 +207,7 @@ if app.config.get("OCR_ENABLED"):
|
||||
extracted_text = []
|
||||
for line in result[0]:
|
||||
extracted_text.append(line[1][0])
|
||||
return render_template("add_account.html", username=extracted_text[2], password=extracted_text[3])
|
||||
return render_template("add_account.html", username=extracted_text[2], password=extracted_text[3], ocr_enabled=app.config.get("OCR_ENABLED"), text_input_enabled=app.config.get("TEXT_INPUT_ENABLED"))
|
||||
except Exception as e:
|
||||
return jsonify({"error": str(e)}), 500
|
||||
|
||||
|
@ -85,7 +85,7 @@ def add_user_account(base_url: str, auth: str, username: str, password: str, str
|
||||
headers = {"Authorization": f"Basic {auth}"}
|
||||
|
||||
response = requests.request("POST", url, headers=headers, data=payload)
|
||||
return "Added successfully" in response.text
|
||||
return response.status_code == 200
|
||||
|
||||
|
||||
def get_user_accounts_count(base_url: str, auth: str) -> int:
|
||||
|
@ -128,7 +128,6 @@
|
||||
this.value = event.text.value;
|
||||
});
|
||||
|
||||
{% if text_input_enabled %}
|
||||
const accountDetailsTextarea = document.getElementById('accountDetails');
|
||||
if (accountDetailsTextarea) {
|
||||
accountDetailsTextarea.addEventListener('input', function() {
|
||||
@ -156,7 +155,6 @@
|
||||
}
|
||||
});
|
||||
}
|
||||
{% endif %}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user