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.="