This commit is contained in:
Bruno Rybársky 2023-08-07 10:09:29 +02:00
parent f6ee043099
commit b7cf477965
No known key found for this signature in database
GPG Key ID: DFE2C061EF985CD4

41
api.php

@ -4,12 +4,13 @@ $mysqllogin = json_decode(file_get_contents("secrets/MysqlLogin.json"), false);
$mysqli = new mysqli('localhost', $mysqllogin->DBUser, $mysqllogin->DBPassword, $mysqllogin->DBName);
$action = $_POST["action"];
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$action = $_POST["action"];
if($action == "login"){
if($action == "login"){
$uname = $_POST["username"];
$pwd = $_POST["password"];
$stmt1 = $mysqli->prepare("SELECT `Password, ID, FullName, Nickname, CanSeeFullNames, CanSeeOthersComments, IsAdmin FROM Users WHERE Username = %s;");
$stmt1 = $mysqli->prepare("SELECT Password, ID, FullName, Nickname, CanSeeFullNames, CanSeeOthersComments, IsAdmin FROM Users WHERE Username = %s;");
$stmt1->bind_param('s', $uname);
$stmt1->bind_result($pwdhash, $uid, $fullname, $nick, $fullnamepriv, $otherscommentspriv, $adminpriv);
$stmt1->execute();
@ -30,18 +31,18 @@ if($action == "login"){
}
echo "Logged in";
return;
}
}
if($action == "logout"){
if($action == "logout"){
session_destroy();
echo "Logged out";
return;
}
}
function processUserRelated($actionin, mysqli $mysqliconn){
function processUserRelated($actionin, mysqli $mysqliconn){
if($actionin == "setnickname"){
$newNick = $_POST["newnick"];
@ -132,10 +133,10 @@ function processUserRelated($actionin, mysqli $mysqliconn){
}
return 0;
}
}
function processCitationRelated($actionin, mysqli $mysqliconn){
function processCitationRelated($actionin, mysqli $mysqliconn){
if($actionin == "getcitations"){
@ -166,10 +167,10 @@ function processCitationRelated($actionin, mysqli $mysqliconn){
}
return 0;
}
}
function processTagsRelated($actionin, mysqli $mysqliconn){
function processTagsRelated($actionin, mysqli $mysqliconn){
if($actionin == "createtag"){
@ -184,9 +185,9 @@ function processTagsRelated($actionin, mysqli $mysqliconn){
}
return 0;
}
}
function processSourcesRelated($actionin, mysqli $mysqliconn){
function processSourcesRelated($actionin, mysqli $mysqliconn){
if($actionin == "createsource"){
@ -201,9 +202,9 @@ function processSourcesRelated($actionin, mysqli $mysqliconn){
}
return 0;
}
}
function processCommentRelated($actionin, mysqli $mysqliconn){
function processCommentRelated($actionin, mysqli $mysqliconn){
if($actionin == "createcomment"){
@ -222,9 +223,9 @@ function processCommentRelated($actionin, mysqli $mysqliconn){
}
return 0;
}
}
if($_SESSION["loggedin"] == 1){
if($_SESSION["loggedin"] == 1){
$citationreturn = processCitationRelated($action, $mysqli);
if($citationreturn != 0){
@ -255,11 +256,11 @@ if($_SESSION["loggedin"] == 1){
echo $userreturn;
return;
}
}
else{
}
else{
echo "Not logged in";
return;
}
}
?>