Implement API for authentication management actions

This commit is contained in:
2022-08-14 12:43:33 +01:00
parent 5123941c79
commit eba2c387f0
5 changed files with 99 additions and 11 deletions

View File

@@ -213,6 +213,39 @@ class API(object):
network["records"] = userinfo.getNumWhoEntries(net)
return dumps(network)
@app.route("/irc/network/auth/", methods=["POST"])
@login_required
def irc_network_recheckauth(self, request):
try:
data = loads(request.content.read())
except JSONDecodeError:
return "Invalid JSON"
if "func" not in data:
return dumps({"success": False, "reason": "no function specified."})
func = data["func"]
if "net" not in data:
return dumps({"success": False, "reason": "no net specified."})
net = data["net"]
if not net or net == "None":
nets = main.network.keys()
else:
if net not in main.network.keys():
return dumps({"success": False, "reason": "no such net."})
nets = [net]
for net_name in nets:
conns = helpers.get_connected_relays(net_name)
if not conns:
return dumps({"success": False, "reason": f"failed to get instances for {net_name}."})
if func == "recheckauth":
for conn in conns:
conn.regPing()
elif func == "resetauth":
for conn in conns:
conn.authenticated = False
conn.regPing()
return dumps({"success": True})
@app.route("/irc/network/<net>/", methods=["DELETE"])
@login_required
def irc_network_delete(self, request, net):