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 (
|
from core.views.manage.threshold.irc import (
|
||||||
ThresholdIRCActions,
|
ThresholdIRCActions,
|
||||||
ThresholdIRCActionsAddNetwork,
|
ThresholdIRCActionsAddNetwork,
|
||||||
|
ThresholdIRCActionsRegistration,
|
||||||
ThresholdIRCAliases,
|
ThresholdIRCAliases,
|
||||||
ThresholdIRCAliasesEdit,
|
ThresholdIRCAliasesEdit,
|
||||||
ThresholdIRCNetworkActions,
|
ThresholdIRCNetworkActions,
|
||||||
|
@ -131,6 +132,16 @@ urlpatterns = [
|
||||||
ThresholdIRCActionsAddNetwork.as_view(),
|
ThresholdIRCActionsAddNetwork.as_view(),
|
||||||
name="threshold_irc_actions_add-network",
|
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(
|
path(
|
||||||
"manage/threshold/irc/network/<str:net>/",
|
"manage/threshold/irc/network/<str:net>/",
|
||||||
ThresholdIRCNetwork.as_view(),
|
ThresholdIRCNetwork.as_view(),
|
||||||
|
|
|
@ -217,3 +217,20 @@ def get_irc_list_info(net):
|
||||||
payload = {}
|
payload = {}
|
||||||
listinfo = threshold_request(url, payload, method="GET")
|
listinfo = threshold_request(url, payload, method="GET")
|
||||||
return listinfo
|
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>Auto</span>
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</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
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
hx-post="{% url 'threshold_irc_network_list' net %}"
|
hx-post="{% url 'threshold_irc_network_list' net %}"
|
||||||
|
@ -44,8 +57,6 @@
|
||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="columns">
|
|
||||||
<div class="column">
|
|
||||||
<form method="POST">
|
<form method="POST">
|
||||||
<div class="field has-addons">
|
<div class="field has-addons">
|
||||||
<div class="control is-expanded has-icons-left">
|
<div class="control is-expanded has-icons-left">
|
||||||
|
@ -67,30 +78,4 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</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>
|
</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>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="modals-here">
|
||||||
|
</div>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
|
@ -30,6 +30,9 @@
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
|
||||||
|
hx-get="{% url 'threshold_irc_actions_registration' %}"
|
||||||
|
hx-trigger="click"
|
||||||
|
hx-target="#modals-here"
|
||||||
class="button is-info">
|
class="button is-info">
|
||||||
<span class="icon-text">
|
<span class="icon-text">
|
||||||
<span class="icon">
|
<span class="icon">
|
||||||
|
|
|
@ -59,7 +59,6 @@ class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View):
|
||||||
def get(self, request, net):
|
def get(self, request, net):
|
||||||
network = threshold.get_irc_network(net)
|
network = threshold.get_irc_network(net)
|
||||||
context = {"network": network}
|
context = {"network": network}
|
||||||
print("CON", context)
|
|
||||||
return render(request, self.template_name, context)
|
return render(request, self.template_name, context)
|
||||||
|
|
||||||
|
|
||||||
|
@ -72,7 +71,7 @@ class ThresholdIRCNetworkInfoEdit(SuperUserRequiredMixin, APIView):
|
||||||
Return the form to edit a network.
|
Return the form to edit a network.
|
||||||
"""
|
"""
|
||||||
network = threshold.get_irc_network(net)
|
network = threshold.get_irc_network(net)
|
||||||
editable = ["auth", "host", "last", "port", "security"]
|
editable = ["auth", "host", "last", "port", "security", "chanlimit"]
|
||||||
context = {
|
context = {
|
||||||
"net": net,
|
"net": net,
|
||||||
"network": {k: v for k, v in network.items() if k in editable},
|
"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)
|
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):
|
class ThresholdIRCAliasesEdit(SuperUserRequiredMixin, APIView):
|
||||||
template_name = "manage/threshold/irc/overview/modals/edit-aliases.html"
|
template_name = "manage/threshold/irc/overview/modals/edit-aliases.html"
|
||||||
parser_classes = [FormParser]
|
parser_classes = [FormParser]
|
||||||
|
@ -483,7 +537,6 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
self.template_name,
|
self.template_name,
|
||||||
{"message": message, "class": message_class},
|
{"message": message, "class": message_class},
|
||||||
)
|
)
|
||||||
print("IRC", nick)
|
|
||||||
if nick:
|
if nick:
|
||||||
messaged = threshold.send_irc_message(
|
messaged = threshold.send_irc_message(
|
||||||
net, num, channel, request.data["msg"], nick=nick
|
net, num, channel, request.data["msg"], nick=nick
|
||||||
|
@ -501,7 +554,6 @@ class ThresholdIRCSendMessage(SuperUserRequiredMixin, APIView):
|
||||||
else:
|
else:
|
||||||
message = messaged["reason"]
|
message = messaged["reason"]
|
||||||
message_class = "danger"
|
message_class = "danger"
|
||||||
print("ERROR", message)
|
|
||||||
|
|
||||||
context = {
|
context = {
|
||||||
"net": net,
|
"net": net,
|
||||||
|
|
Loading…
Reference in New Issue