From 920376995e36dcc14bdfa1398c9bea173601f7bd Mon Sep 17 00:00:00 2001 From: mrkubax10 Date: Sun, 10 Sep 2023 14:30:40 +0200 Subject: [PATCH] Frontend: Add user panel --- database_settings.sql | 1 + frontend_routes.pm | 85 +++++++++++++++++++++++++++++++++++++++++++ templates/panel.html | 20 ++++++++++ 3 files changed, 106 insertions(+) create mode 100644 templates/panel.html diff --git a/database_settings.sql b/database_settings.sql index 2cc52b8..76c3601 100644 --- a/database_settings.sql +++ b/database_settings.sql @@ -8,6 +8,7 @@ create table channels(id int primary key not null, create table users(id int primary key not null, name text not null, password text not null, + privileges int not null, -- 0 - normal user, 1 - moderator, 2 - administrator accessor int -- foreign key in accessors table ); diff --git a/frontend_routes.pm b/frontend_routes.pm index 493f50d..592ba40 100644 --- a/frontend_routes.pm +++ b/frontend_routes.pm @@ -123,6 +123,91 @@ sub handlePath { frontend::redirect($aClient, "/"); return 1; } + when("/panel") { + if(!defined($aRequest->{"cookies"}{"session"}) || !frontend_session::isValidSession($aRequest->{"cookies"}{"session"})) { + frontend::redirect($aClient, "/"); + return 1; + } + my $session = $frontend_session::sessions{$aRequest->{"cookies"}{"session"}}; + my $query = $aConnection->prepare(qq(select privileges from users where name=?;)); + $query->execute($session->{"username"}); + my @row = $query->fetchrow_array(); + my $privileges = $row[0]; + + my $manageChannelAccess = ""; + if($privileges>=1) { # moderator + $manageChannelAccess.="

Manage channel access

"; + $manageChannelAccess.="
"; + $manageChannelAccess.=""; + $manageChannelAccess.="
"; + $manageChannelAccess.=" "; + $manageChannelAccess.=""; + $manageChannelAccess.="
"; + } + + my $manageServers = ""; + if($privileges==2) { + $manageServers.="

Manage servers

"; + $manageServers.="
"; + $manageServers.="
"; + $manageServers.=" "; + $manageServers.="
"; + $manageServers.=""; + $manageServers.="
"; + } + + my $manageChannels = ""; + if($privileges==2) { + $manageChannels.="

Manage channels

"; + $manageChannels.="
"; + $manageChannels.=" at "; + $manageChannels.="
"; + $manageChannels.=""; + $manageChannels.="
"; + } + + my $addUser = ""; + if($privileges==2) { + $addUser.="

Add user

"; + $addUser.="
"; + $addUser.="
"; + $addUser.="
"; + $addUser.="
"; + $addUser.=""; + $addUser.="
"; + } + + frontend::sendTemplate("templates/panel.html", $aClient, {"username"=>$session->{"username"}, "manageChannelAccess"=>$manageChannelAccess, "manageServers"=>$manageServers, "manageChannels"=>$manageChannels, "addUser"=>$addUser}); + return 1; + } when("/view_logs") { my $channelID = $aRequest->{"path"}{"parameters"}{"channel"}; if(!defined($channelID)) { diff --git a/templates/panel.html b/templates/panel.html new file mode 100644 index 0000000..b567ba3 --- /dev/null +++ b/templates/panel.html @@ -0,0 +1,20 @@ + + + + {{username}}'s panel + + +

User panel

+ Back +

Change password

+
+
+
+ +
+ {{manageChannelAccess}} + {{manageServers}} + {{manageChannels}} + {{addUser}} + +