From b1041332ef0437031839d4e6ad64f4c7b797d6f8 Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Wed, 17 May 2023 10:51:15 +0300 Subject: auth: Import/Delete Anonymous Collections Integrate import/delete of anonymous collection when user is authenticated. --- wqflask/wqflask/collect.py | 23 ++++++++++++++- wqflask/wqflask/oauth2/toplevel.py | 2 +- wqflask/wqflask/templates/collections/list.html | 3 +- wqflask/wqflask/templates/index_page.html | 37 ++++++++++++++++++++++++- wqflask/wqflask/views.py | 21 +++++++++----- 5 files changed, 75 insertions(+), 11 deletions(-) diff --git a/wqflask/wqflask/collect.py b/wqflask/wqflask/collect.py index b64270e0..ad0820c2 100644 --- a/wqflask/wqflask/collect.py +++ b/wqflask/wqflask/collect.py @@ -27,7 +27,8 @@ from wqflask.oauth2 import session from wqflask.oauth2.session import session_info from wqflask.oauth2.checks import user_logged_in from wqflask.oauth2.request_utils import process_error -from wqflask.oauth2.client import oauth2_get, no_token_get, no_token_post +from wqflask.oauth2.client import ( + oauth2_get, oauth2_post, no_token_get, no_token_post) Redis = get_redis_conn() @@ -188,6 +189,26 @@ def list_collections(): **user_collections, **anon_collections) +@app.route("/collections/handle_anonymous", methods=["POST"]) +def handle_anonymous_collections(): + """Handle any anonymous collection on logging in.""" + choice = request.form.get("anon_choice") + if choice not in ("import", "delete"): + flash("Invalid choice!", "alert-danger") + return redirect("/") + def __impdel_error__(err): + error = process_error(err) + flash(f"{error['error']}: {error['error_description']}", + "alert-danger") + return redirect("/") + def __impdel_success__(msg): + flash(f"Success: {msg['message']}", "alert-success") + return redirect("/") + return oauth2_post( + f"oauth2/user/collections/anonymous/{choice}", + json={ + "anon_id": str(session_info()["anon_id"]) + }).either(__impdel_error__, __impdel_success__) @app.route("/collections/remove", methods=('POST',)) def remove_traits(): diff --git a/wqflask/wqflask/oauth2/toplevel.py b/wqflask/wqflask/oauth2/toplevel.py index ef9ce3db..04a08870 100644 --- a/wqflask/wqflask/oauth2/toplevel.py +++ b/wqflask/wqflask/oauth2/toplevel.py @@ -35,7 +35,7 @@ def authorisation_code(): "token": session.user_token(), "logged_in": True }) - return redirect(url_for("oauth2.user.user_profile")) + return redirect("/") code = request.args.get("code", "") if bool(code): diff --git a/wqflask/wqflask/templates/collections/list.html b/wqflask/wqflask/templates/collections/list.html index 7e5c5330..437b0cc3 100644 --- a/wqflask/wqflask/templates/collections/list.html +++ b/wqflask/wqflask/templates/collections/list.html @@ -65,7 +65,8 @@ {%endif%} {% if collections|length > 0 %} -
diff --git a/wqflask/wqflask/templates/index_page.html b/wqflask/wqflask/templates/index_page.html index aad5d109..12503326 100755 --- a/wqflask/wqflask/templates/index_page.html +++ b/wqflask/wqflask/templates/index_page.html @@ -54,7 +54,42 @@ |
---|