From 7524691b79e1599a04bbbaa3dd9304b8f964e70f Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 11 Feb 2022 18:19:10 +0700 Subject: [PATCH] implement API token revoke --- tubearchivist/home/templates/home/settings.html | 1 + tubearchivist/home/views.py | 6 +++++- tubearchivist/static/script.js | 8 ++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/tubearchivist/home/templates/home/settings.html b/tubearchivist/home/templates/home/settings.html index 83829f3..740ca40 100644 --- a/tubearchivist/home/templates/home/settings.html +++ b/tubearchivist/home/templates/home/settings.html @@ -120,6 +120,7 @@

API token:

{{ api_token }}

+
diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index a0cac87..660ec73 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -715,7 +715,6 @@ class SettingsView(View): """get existing or create new token of user""" # pylint: disable=no-member token = Token.objects.get_or_create(user=request.user)[0] - print(token) return token @staticmethod @@ -758,6 +757,11 @@ def process(request): if request.method == "POST": current_user = request.user.id post_dict = json.loads(request.body.decode()) + if post_dict.get("reset-token"): + print("revoke API token") + request.user.auth_token.delete() + return JsonResponse({"success": True}) + post_handler = PostData(post_dict, current_user) if post_handler.to_exec: task_result = post_handler.run_task() diff --git a/tubearchivist/static/script.js b/tubearchivist/static/script.js index db91621..22cfd56 100644 --- a/tubearchivist/static/script.js +++ b/tubearchivist/static/script.js @@ -235,6 +235,14 @@ function findPlaylists(button) { }, 500); } +function resetToken() { + var payload = JSON.stringify({'reset-token': true}); + sendPost(payload); + var message = document.createElement("p"); + message.innerText = "Token revoked"; + document.getElementById("text-reveal").replaceWith(message); +} + // delete from file system function deleteConfirm() { to_show = document.getElementById("delete-button");