From fca9e1d060d5cb9ae0dba59236f2cec36befaee5 Mon Sep 17 00:00:00 2001 From: vadym Novoselskyi Date: Fri, 27 Sep 2024 11:10:29 +0200 Subject: [PATCH] Add M6 3/3 --- www/public/M6/egyTalk/api/auth.php | 3 +- www/public/M6/egyTalk/api/getPostsByUID.php | 26 ++++++++ www/public/M6/egyTalk/api/getUserByUID.php | 21 +++++++ .../egyTalk/controller/userManipulation.php | 2 +- www/public/M6/egyTalk/index.php | 13 +++- www/public/M6/egyTalk/model/dbEgyTalk.php | 59 +++++++++---------- 6 files changed, 89 insertions(+), 35 deletions(-) create mode 100644 www/public/M6/egyTalk/api/getPostsByUID.php create mode 100644 www/public/M6/egyTalk/api/getUserByUID.php diff --git a/www/public/M6/egyTalk/api/auth.php b/www/public/M6/egyTalk/api/auth.php index 902ad25..985f9ba 100644 --- a/www/public/M6/egyTalk/api/auth.php +++ b/www/public/M6/egyTalk/api/auth.php @@ -12,7 +12,7 @@ $response['userdata'] = null; //$user = $db->getUserFromUid($_SESSION['uid']); //} if (isset($_POST['username'], $_POST['password'])) { - $user = $db->auth($_POST['username'], $_POST['password']); + $user = $db->auth($_POST['username'], $_POST['password'], false); } if (isset($user) && !empty($user)) { @@ -23,7 +23,6 @@ if (isset($user) && !empty($user)) { } if(!$response['auth']) header('HTTP/1.0 401 Unauthorized'); - header('Access-Control-Allow-Credentials: true'); header('Content-Type: application/json'); diff --git a/www/public/M6/egyTalk/api/getPostsByUID.php b/www/public/M6/egyTalk/api/getPostsByUID.php new file mode 100644 index 0000000..b28c72b --- /dev/null +++ b/www/public/M6/egyTalk/api/getPostsByUID.php @@ -0,0 +1,26 @@ +getUserPosts($uid); + + for($i = 0; $i < sizeof($response['posts']); $i++) { + $comments = $db->getComments($response['posts'][$i]['pid']); + $response['posts'][$i]['comments'] = $comments; + } +} +// Behövs för session-cookies och anger att formatet är json +header('Access-Control-Allow-Credentials: true'); +header('Content-Type: application/json'); + +echo json_encode($response, JSON_UNESCAPED_UNICODE); diff --git a/www/public/M6/egyTalk/api/getUserByUID.php b/www/public/M6/egyTalk/api/getUserByUID.php new file mode 100644 index 0000000..324e270 --- /dev/null +++ b/www/public/M6/egyTalk/api/getUserByUID.php @@ -0,0 +1,21 @@ +getUserByUID($uid); +} +// Behövs för session-cookies och anger att formatet är json +header('Access-Control-Allow-Credentials: true'); +header('Content-Type: application/json'); + +echo json_encode($response, JSON_UNESCAPED_UNICODE); diff --git a/www/public/M6/egyTalk/controller/userManipulation.php b/www/public/M6/egyTalk/controller/userManipulation.php index 6e8acef..93c646b 100644 --- a/www/public/M6/egyTalk/controller/userManipulation.php +++ b/www/public/M6/egyTalk/controller/userManipulation.php @@ -14,7 +14,7 @@ function login() $username = filter_input(INPUT_POST, 'username', FILTER_UNSAFE_RAW); $password = $_POST['password']; - $result = $db->login($username, $password); + $result = $db->auth($username, $password, true); if ($result == []) { header("Location: ../login.html"); diff --git a/www/public/M6/egyTalk/index.php b/www/public/M6/egyTalk/index.php index 5230a16..fef587d 100644 --- a/www/public/M6/egyTalk/index.php +++ b/www/public/M6/egyTalk/index.php @@ -18,13 +18,24 @@ echo "

Your name " . $_SESSION['name'] . "

"; ?> -
+
+ getPosts.php +
+ + +
+ +
+ + +
+