Add a button to delete all API Keys.

This commit is contained in:
george 2022-01-23 18:38:54 +00:00
parent e73288354d
commit 65531b5c63
No known key found for this signature in database
GPG Key ID: D30164B91DE6EEE3
3 changed files with 44 additions and 4 deletions

View File

@ -41,17 +41,18 @@ def api_key():
Session.commit()
flash(f"API Key {name} has been deleted", "success")
return redirect(url_for("dashboard.api_key"))
elif request.form.get("form-name") == "create":
if new_api_key_form.validate():
new_api_key = ApiKey.create(
name=new_api_key_form.name.data, user_id=current_user.id
)
Session.commit()
flash(f"New API Key {new_api_key.name} has been created", "success")
return redirect(url_for("dashboard.api_key"))
elif request.form.get("form-name") == "delete-all":
ApiKey.deleteall(current_user.id)
Session.commit()
flash("All API Keys have been deleted", "success")
return redirect(url_for("dashboard.api_key"))

View File

@ -1966,6 +1966,10 @@ class ApiKey(Base, ModelMixin):
return super().create(user_id=user_id, name=name, code=code, **kwargs)
@classmethod
def deleteall(cls, user_id):
Session.query(cls).filter(cls.user_id == user_id).delete()
class CustomDomain(Base, ModelMixin):
__tablename__ = "custom_domain"

View File

@ -22,6 +22,16 @@
API Keys should be kept secret and treated like passwords, they can be used to gain access to your account.
</div>
{% if api_keys|length > 0 %}
<form method="post">
<input type="hidden" name="form-name" value="delete-all">
<span class="delete btn btn-danger delete-all-api-keys">
Delete All &nbsp; &nbsp; <i class="fe fe-trash"></i>
</span>
</form>
<br>
{% endif %}
<div class="row">
{% for api_key in api_keys %}
<div class="col-12 col-lg-6">
@ -118,6 +128,31 @@
})
});
$(".delete-all-api-keys").on("click", function (e) {
let that = $(this);
bootbox.confirm({
message: "This will delete all API Keys, they will all stop working, are you sure?",
buttons: {
confirm: {
label: 'Delete All',
className: 'btn-danger'
},
cancel: {
label: 'Cancel',
className: 'btn-outline-primary'
}
},
callback: function (result) {
if (result) {
that.closest("form").submit();
}
}
})
});
$(".toggle-api-key").on('click', function (event) {