mirror of
https://github.com/tubearchivist/tubearchivist-frontend.git
synced 2024-12-22 18:00:17 +00:00
implement API token revoke
This commit is contained in:
parent
f1de8db4f3
commit
7524691b79
@ -120,6 +120,7 @@
|
||||
<p>API token: <button type="button" onclick="textReveal()" id="text-reveal-button">Show</button></p>
|
||||
<div id="text-reveal" class="description-text">
|
||||
<p>{{ api_token }}</p>
|
||||
<button class="danger-button" type="button" onclick="resetToken()">Revoke</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-item">
|
||||
|
@ -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()
|
||||
|
@ -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");
|
||||
|
Loading…
Reference in New Issue
Block a user