Implement re-checking and resetting authentication status

This commit is contained in:
Mark Veidemanis 2022-08-14 12:43:13 +01:00
parent 67afe92195
commit 3671d94e59
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 96 additions and 22 deletions

View File

@ -30,6 +30,7 @@ from core.views.manage.threshold.irc import (
ThresholdIRCActions,
ThresholdIRCActionsAddNetwork,
ThresholdIRCActionsRegistration,
ThresholdIRCActionsRegistrationAuth,
ThresholdIRCAliases,
ThresholdIRCAliasesEdit,
ThresholdIRCNetworkActions,
@ -135,6 +136,11 @@ urlpatterns = [
ThresholdIRCActionsAddNetwork.as_view(),
name="threshold_irc_actions_add-network",
),
path(
"manage/threshold/irc/actions/registration/auth/",
ThresholdIRCActionsRegistrationAuth.as_view(),
name="threshold_irc_actions_registration_auth",
),
path(
"manage/threshold/irc/actions/registration/<str:net>/",
ThresholdIRCActionsRegistration.as_view(),

View File

@ -246,3 +246,10 @@ def irc_enable_auth(net, num):
payload = {}
enabled = threshold_request(url, payload, method="POST")
return enabled
def irc_check_auth(data):
url = "irc/network/auth"
payload = data
updated = threshold_request(url, payload, method="POST")
return updated

View File

@ -6,7 +6,39 @@
<div class="modal-background"></div>
<div class="modal-content">
<div class="box">
{% include 'manage/threshold/partials/notify.html' %}
<h4 class="subtitle is-4">Registration</h4>
<div class="buttons">
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_actions_registration_auth' %}"
hx-vals='{"net": "{{ net }}", "func": "recheckauth"}'
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-wrench"></i>
</span>
<span>Check auth</span>
</span>
</button>
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_actions_registration_auth' %}"
hx-vals='{"net": "{{ net }}", "func": "resetauth"}'
hx-trigger="click"
hx-target="#modals-here"
class="button is-info">
<span class="icon-text">
<span class="icon">
<i class="fa-solid fa-wrench"></i>
</span>
<span>Reset auth</span>
</span>
</button>
</div>
{% if unreg %}
<form
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-put="{% url 'threshold_irc_actions_registration_net' net %}"
@ -31,6 +63,9 @@
<button type="submit" class="button is-info modal-close-button">Submit</button>
{# <script>activateButtons();</script> #}
</form>
{% else %}
<p>No unregistered relays.</p>
{% endif %}
</div>
<button class="modal-close is-large" aria-label="close"></button>

View File

@ -447,6 +447,32 @@ class ThresholdIRCActionsRegistration(SuperUserRequiredMixin, APIView):
return render(request, template_name, context)
class ThresholdIRCActionsRegistrationAuth(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/network/modals/registration.html"
parser_classes = [FormParser]
def post(self, request):
"""
Confirm registration for networks.
"""
updated = threshold.irc_check_auth(request.data)
message = "Re-checked authentication successfully."
message_class = "success"
if not updated["success"]:
message = updated["reason"]
message_class = "danger"
context = {
"message": message,
"class": message_class,
}
if "net" in request.data:
context["net"] = request.data["net"]
return render(request, self.template_name, context)
class ThresholdIRCAliasesEdit(SuperUserRequiredMixin, APIView):
template_name = "manage/threshold/irc/overview/modals/edit-aliases.html"
parser_classes = [FormParser]