Implement updating network registration
This commit is contained in:
parent
b2121913b6
commit
779eb3697c
11
app/urls.py
11
app/urls.py
|
@ -29,6 +29,7 @@ from core.views.manage.threshold.irc import (
|
|||
from core.views.manage.threshold.irc import (
|
||||
ThresholdIRCActions,
|
||||
ThresholdIRCActionsAddNetwork,
|
||||
ThresholdIRCActionsRegistration,
|
||||
ThresholdIRCAliases,
|
||||
ThresholdIRCAliasesEdit,
|
||||
ThresholdIRCNetworkActions,
|
||||
|
@ -131,6 +132,16 @@ urlpatterns = [
|
|||
ThresholdIRCActionsAddNetwork.as_view(),
|
||||
name="threshold_irc_actions_add-network",
|
||||
),
|
||||
path(
|
||||
"manage/threshold/irc/actions/registration/<str:net>/",
|
||||
ThresholdIRCActionsRegistration.as_view(),
|
||||
name="threshold_irc_actions_registration_net",
|
||||
),
|
||||
path(
|
||||
"manage/threshold/irc/actions/registration/",
|
||||
ThresholdIRCActionsRegistration.as_view(),
|
||||
name="threshold_irc_actions_registration",
|
||||
),
|
||||
path(
|
||||
"manage/threshold/irc/network/<str:net>/",
|
||||
ThresholdIRCNetwork.as_view(),
|
||||
|
|
|
@ -217,3 +217,20 @@ def get_irc_list_info(net):
|
|||
payload = {}
|
||||
listinfo = threshold_request(url, payload, method="GET")
|
||||
return listinfo
|
||||
|
||||
|
||||
def irc_get_unreg(net=None):
|
||||
if net:
|
||||
url = f"irc/reg/{net}"
|
||||
else:
|
||||
url = "irc/reg"
|
||||
payload = {}
|
||||
unreg = threshold_request(url, payload, method="GET")
|
||||
return unreg
|
||||
|
||||
|
||||
def irc_confirm_accounts(tokens):
|
||||
url = "irc/reg"
|
||||
payload = tokens
|
||||
updated = threshold_request(url, payload, method="PUT")
|
||||
return updated
|
||||
|
|
|
@ -29,6 +29,19 @@
|
|||
<span>Auto</span>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-get="{% url 'threshold_irc_actions_registration_net' net %}"
|
||||
hx-trigger="click"
|
||||
hx-target="#modals-here"
|
||||
class="button is-info">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
<i class="fa-solid fa-list"></i>
|
||||
</span>
|
||||
<span>Registration</span>
|
||||
</span>
|
||||
</button>
|
||||
<button
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-post="{% url 'threshold_irc_network_list' net %}"
|
||||
|
@ -44,8 +57,6 @@
|
|||
</span>
|
||||
</button>
|
||||
</div>
|
||||
<div class="columns">
|
||||
<div class="column">
|
||||
<form method="POST">
|
||||
<div class="field has-addons">
|
||||
<div class="control is-expanded has-icons-left">
|
||||
|
@ -67,30 +78,4 @@
|
|||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<div class="column">
|
||||
<form method="POST">
|
||||
<div class="field has-addons">
|
||||
<div class="control is-expanded has-icons-left">
|
||||
<input class="input" name="num" type="text" placeholder="Channel limit">
|
||||
<span class="icon is-small is-left">
|
||||
<i class="fa-brands fa-unity"></i>
|
||||
</span>
|
||||
</div>
|
||||
<div class="control">
|
||||
<button
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
class="button is-warning is-fullwidth"
|
||||
hx-put="{% url 'threshold_irc_network_actions_add_relay' net %}"
|
||||
hx-trigger="click"
|
||||
hx-target="#actions"
|
||||
hx-swap="outerHTML">
|
||||
Set
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
|
@ -0,0 +1,47 @@
|
|||
{% load index %}
|
||||
{% load static %}
|
||||
|
||||
<script src="{% static 'modal.js' %}"></script>
|
||||
<div id="modal" class="modal is-active is-clipped">
|
||||
<div class="modal-background"></div>
|
||||
<div class="modal-content">
|
||||
<div class="box">
|
||||
<h4 class="subtitle is-4">Registration</h4>
|
||||
<form
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-put="{% url 'threshold_irc_actions_registration_net' net %}"
|
||||
hx-target="#actions"
|
||||
hx-swap="outerHTML">
|
||||
{{ unreg }}
|
||||
{% for network, items in unreg.items %}
|
||||
<h4 class="title is-4">{{ network }}</h4>
|
||||
{% for nick, num in items %}
|
||||
<div class="field">
|
||||
<label class="label">{{ nick }}/{{ num }}</label>
|
||||
<div class="control">
|
||||
<input class="input" type="text" name="{{ network }}|{{ num }}" placeholder="Enter token">
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
<button
|
||||
type="button"
|
||||
class="button is-light modal-close-button">
|
||||
Cancel
|
||||
</button>
|
||||
<button type="submit" class="button is-info modal-close-button">Submit</button>
|
||||
{# <script>activateButtons();</script> #}
|
||||
</form>
|
||||
|
||||
</div>
|
||||
<button class="modal-close is-large" aria-label="close"></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -112,4 +112,6 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="modals-here">
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
|
|
@ -30,6 +30,9 @@
|
|||
</button>
|
||||
<button
|
||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||
hx-get="{% url 'threshold_irc_actions_registration' %}"
|
||||
hx-trigger="click"
|
||||
hx-target="#modals-here"
|
||||
class="button is-info">
|
||||
<span class="icon-text">
|
||||
<span class="icon">
|
||||
|
|
|
@ -59,7 +59,6 @@ class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View):
|
|||
def get(self, request, net):
|
||||
network = threshold.get_irc_network(net)
|
||||
context = {"network": network}
|
||||
print("CON", context)
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
|
||||
|
@ -72,7 +71,7 @@ class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView):
|
|||
Return the form to edit a network.
|
||||
"""
|
||||
network = threshold.get_irc_network(net)
|
||||
editable = ["auth", "host", "last", "port", "security"]
|
||||
editable = ["auth", "host", "last", "port", "security", "chanlimit"]
|
||||
context = {
|
||||
"net": net,
|
||||
"network": {k: v for k, v in network.items() if k in editable},
|
||||
|
@ -287,6 +286,61 @@ class ThresholdIRCActionsAddNetwork(SuperUserRequiredMixin, APIView):
|
|||
return render(request, template_name, context)
|
||||
|
||||
|
||||
class ThresholdIRCActionsRegistration(SuperUserRequiredMixin, APIView):
|
||||
template_name = "manage/threshold/irc/network/modals/registration.html"
|
||||
parser_classes = [FormParser]
|
||||
|
||||
def get(self, request, net=None):
|
||||
"""
|
||||
Get registration modal
|
||||
"""
|
||||
unreg = threshold.irc_get_unreg(net)
|
||||
message = None
|
||||
message_class = None
|
||||
if not unreg:
|
||||
message = "Could not get registration status."
|
||||
message_class = "danger"
|
||||
elif not unreg["success"]:
|
||||
if "reason" in unreg:
|
||||
message = unreg["reason"]
|
||||
message_class = "danger"
|
||||
else:
|
||||
message = "Getting registration status failed."
|
||||
message_class = "danger"
|
||||
context = {
|
||||
"net": net,
|
||||
"message": message,
|
||||
"class": message_class,
|
||||
}
|
||||
if not message_class == "danger":
|
||||
context["unreg"] = unreg["unreg"]
|
||||
return render(request, self.template_name, context)
|
||||
|
||||
def put(self, request, net=None):
|
||||
"""
|
||||
Confirm registration for networks.
|
||||
"""
|
||||
if request.resolver_match.url_name == "threshold_irc_actions_registration_net":
|
||||
template_name = "manage/threshold/irc/network/actions.html"
|
||||
else:
|
||||
template_name = "manage/threshold/irc/overview/actions.html"
|
||||
updated = threshold.irc_confirm_accounts(request.data)
|
||||
|
||||
message = "Registration confirmed successfully."
|
||||
message_class = "success"
|
||||
|
||||
if not updated["success"]:
|
||||
message = updated["reason"]
|
||||
message_class = "danger"
|
||||
|
||||
context = {
|
||||
"net": net,
|
||||
"message": message,
|
||||
"class": message_class,
|
||||
}
|
||||
return render(request, template_name, context)
|
||||
|
||||
|
||||
class ThresholdIRCAliasesEdit(SuperUserRequiredMixin, APIView):
|
||||
template_name = "manage/threshold/irc/overview/modals/edit-aliases.html"
|
||||
parser_classes = [FormParser]
|
||||
|
@ -483,7 +537,6 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
|||
self.template_name,
|
||||
{"message": message, "class": message_class},
|
||||
)
|
||||
print("IRC", nick)
|
||||
if nick:
|
||||
messaged = threshold.send_irc_message(
|
||||
net, num, channel, request.data["msg"], nick=nick
|
||||
|
@ -501,7 +554,6 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
|||
else:
|
||||
message = messaged["reason"]
|
||||
message_class = "danger"
|
||||
print("ERROR", message)
|
||||
|
||||
context = {
|
||||
"net": net,
|
||||
|
|
Loading…
Reference in New Issue