Added the ability to edit and delete posts which includes uploading of images for the posts and managing those images

Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
2023-07-12 03:29:56 +01:00
parent be5e047f51
commit 3b71ba4d23
26 changed files with 1549 additions and 315 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ class userData
public function createToken(string $username): string
{
$now = time();
$future = strtotime('+6 hour', $now);
$future = strtotime('+2 day', $now);
$secretKey = getSecretKey();
$payload = [
"jti" => $username,
+18 -5
View File
@@ -36,15 +36,19 @@ class userRoutes implements routesInterface
if (empty($data["username"]) || empty($data["password"]))
{
// uh oh userData sent empty data
// uh oh user sent empty data
return $response->withStatus(400);
}
if ($this->user->checkUser($data["username"], $data["password"]))
{
// yay, userData is logged in
// yay, user is logged in
$_SESSION["token"] = $this->user->createToken($data["username"]);
$_SESSION["username"] = $data["username"];
$inactive = 60 * 60 * 48; // 2 days
$_SESSION["timeout"] = time() + $inactive;
$response->getBody()->write(json_encode(array("token" => $_SESSION["token"])));
return $response;
}
@@ -62,15 +66,24 @@ class userRoutes implements routesInterface
{
if (empty($_SESSION["token"]) && empty($_SESSION["username"]))
{
// uh oh userData not logged in
// uh oh user not logged in
return $response->withStatus(401);
}
$inactive = 60 * 60 * 48; // 2 days
$sessionLife = time() - $_SESSION["timeout"];
if ($sessionLife > $inactive)
{
// uh oh user session expired
session_destroy();
return $response->withStatus(401);
}
if (empty($_SESSION["token"]))
{
// userData is logged in but no token was created
// user is logged in but no token was created
$_SESSION["token"] = $this->user->createToken($_SESSION["username"]);
return $response;
return $response->withStatus(201);
}
$response->getBody()->write(json_encode(array("token" => $_SESSION["token"])));