Frontend: Panel cleanup

This commit is contained in:
mrkubax10 2023-09-14 18:22:14 +02:00
parent 61ea7c8eec
commit 3155946a67
2 changed files with 36 additions and 37 deletions

View File

@ -193,6 +193,7 @@ sub handlePath {
my $privileges = $row[0];
my $manageChannelAccess = "";
my $addUser = "";
if($privileges>=1) { # moderator
$manageChannelAccess.="<h3>Manage channel access</h3>";
$manageChannelAccess.="<form action=\"manage_access_action\" method=\"POST\">";
@ -221,49 +222,47 @@ sub handlePath {
$manageChannelAccess.="<input name=\"grant\" type=\"submit\" value=\"Grant access\" /> ";
$manageChannelAccess.="<input name=\"revoke\" type=\"submit\" value=\"Revoke access\" />";
$manageChannelAccess.="</form>";
}
my $manageServers = "";
if($privileges==2) {
$manageServers.="<h3>Manage servers</h3>";
$manageServers.="<form action=\"manage_server_action\" method=\"POST\">";
$manageServers.="<input name=\"name\" type=\"text\" placeholder=\"Server name\" /><br />";
$manageServers.="<input name=\"address\" type=\"text\" placeholder=\"Server address\" /> ";
$manageServers.="<input name=\"port\" type=\"number\" placeholder=\"Server port (optional)\" /><br />";
$manageServers.="<input type=\"submit\" value=\"Add\" />";
$manageServers.="</form>";
}
my $manageChannels = "";
if($privileges==2) {
$manageChannels.="<h3>Manage channels</h3>";
$manageChannels.="<form action=\"manage_channel_action\" method=\"POST\">";
$manageChannels.="<input name=\"channel\" type=\"text\" placeholder=\"Channel\" /> at ";
$manageChannels.="<select name=\"server\">";
$query = $aConnection->prepare(qq(select id, name from servers;));
$query->execute();
while(@row = $query->fetchrow_array()) {
my $id = $row[0];
my $name = $row[1];
$manageChannels.="<option value=\"$id\">$name</option>";
}
$manageChannels.="</select><br />";
$manageChannels.="<input type=\"submit\" value=\"Add\" />";
$manageChannels.="</form>";
}
my $addUser = "";
if($privileges==2) {
$addUser.="<h3>Add user</h3>";
$addUser.="<form action=\"add_user_action\" method=\"POST\">";
$addUser.="<input name=\"name\" type=\"text\" placeholder=\"Username\" /><br />";
$addUser.="<input name=\"password\" type=\"password\" placeholder=\"Password\" /><br />";
$addUser.="<input name=\"confirmPassword\" type=\"password\" placeholder=\"Confirm password\" /><br />";
$addUser.="<input name=\"operator\" type=\"checkbox\" />Operator<br />";
$addUser.="<input type=\"submit\" value=\"Add\" />";
$addUser.="</form>";
}
frontend::sendTemplate("templates/panel.html", $aClient, {"username"=>$session->{"username"}, "manageChannelAccess"=>$manageChannelAccess, "manageServers"=>$manageServers, "manageChannels"=>$manageChannels, "addUser"=>$addUser});
my $addServer = "";
if($privileges==2) {
$addServer.="<h3>Add server</h3>";
$addServer.="<form action=\"add_server_action\" method=\"POST\">";
$addServer.="<input name=\"name\" type=\"text\" placeholder=\"Server name\" /><br />";
$addServer.="<input name=\"address\" type=\"text\" placeholder=\"Server address\" /> ";
$addServer.="<input name=\"port\" type=\"number\" placeholder=\"Server port (optional)\" /><br />";
$addServer.="<input type=\"submit\" value=\"Add\" />";
$addServer.="</form>";
}
my $addChannel = "";
if($privileges==2) {
$addChannel.="<h3>Add channel</h3>";
$addChannel.="<form action=\"add_channel_action\" method=\"POST\">";
$addChannel.="<input name=\"channel\" type=\"text\" placeholder=\"Channel\" /> at ";
$addChannel.="<select name=\"server\">";
$query = $aConnection->prepare(qq(select id, name from servers;));
$query->execute();
while(@row = $query->fetchrow_array()) {
my $id = $row[0];
my $name = $row[1];
$addChannel.="<option value=\"$id\">$name</option>";
}
$addChannel.="</select><br />";
$addChannel.="<input type=\"submit\" value=\"Add\" />";
$addChannel.="</form>";
}
frontend::sendTemplate("templates/panel.html", $aClient, {"username"=>$session->{"username"}, "manageChannelAccess"=>$manageChannelAccess, "addUser"=>$addUser, "addServer"=>$addServer, "addChannel"=>$addChannel});
return 1;
}
when("/change_password_action") {
@ -310,7 +309,7 @@ sub handlePath {
return 1;
}
when("/manage_server_action") {
when("/add_server_action") {
if(!defined($aRequest->{"cookies"}{"session"}) || !frontend_session::isValidSession($aRequest->{"cookies"}{"session"})) {
frontend::redirect($aClient, "/");
return 1;
@ -369,7 +368,7 @@ sub handlePath {
logger::createLogger($parameters{"name"}, $parameters{"address"}, $port, ());
return 1;
}
when("/manage_channel_action") {
when("/add_channel_action") {
if(!defined($aRequest->{"cookies"}{"session"}) || !frontend_session::isValidSession($aRequest->{"cookies"}{"session"})) {
frontend::redirect($aClient, "/");
return 1;

View File

@ -13,8 +13,8 @@
<input type="submit" value="Change" />
</form>
{{manageChannelAccess}}
{{manageServers}}
{{manageChannels}}
{{addUser}}
{{addServer}}
{{addChannel}}
</body>
</html>