Completed reset password section and added in eye button to toggle between shown and hidden password.

Signed-off-by: rodude123 <rodude123@gmail.com>
This commit is contained in:
2022-09-14 13:35:58 +01:00
parent d8e16e8de1
commit d963904174
14 changed files with 191 additions and 42 deletions
+40 -12
View File
@@ -37,10 +37,10 @@ $errorMiddleware = $app->addErrorMiddleware(true, true, true);
$app->setBasePath("/api");
// return all responses as JSON
$app->add(function($request, $handler) {
/*$app->add(function($request, $handler) {
$response = $handler->handle($request);
return $response->withHeader("Content-Type", "application/json");
});
});*/
$timelineData = new timelineData();
$projectData = new projectData();
@@ -100,8 +100,7 @@ $app->post("/contact", function (Request $request, Response $response)
if (!filter_var($data["email"], FILTER_VALIDATE_EMAIL))
{
$response->getBody()->write(json_encode(array("errorMessage" => "Email is not the correct format")));
$response = $response->withStatus(400);
return $response;
return $response->withStatus(400);
}
// email form filler/conatcter
@@ -261,7 +260,8 @@ $app->post("/contact", function (Request $request, Response $response)
return $response->withStatus(201);
});
$app->post("/user/login", function (Request $request, Response $response) {
$app->post("/user/login", function (Request $request, Response $response)
{
global $user;
@@ -276,7 +276,7 @@ $app->post("/user/login", function (Request $request, Response $response) {
if ($user->checkUser($data["username"], $data["password"]))
{
// yay user is logged in
// yay, user is logged in
$_SESSION["token"] = $user->createToken();
$_SESSION["username"] = $data["username"];
return $response;
@@ -284,8 +284,8 @@ $app->post("/user/login", function (Request $request, Response $response) {
return $response->withStatus(401);
});
$app->get("/user/isLoggedIn", function (Request $request, Response $response) {
$app->get("/user/isLoggedIn", function (Request $request, Response $response)
{
global $user;
if (empty($_SESSION["token"]) && empty($_SESSION["username"]))
@@ -299,9 +299,11 @@ $app->get("/user/isLoggedIn", function (Request $request, Response $response) {
// user is logged in but no token was created
$_SESSION["token"] = $user->createToken();
return $response;
}
}
$response->getBody()->write(json_encode(array("token" => $_SESSION["token"])));
return $response;
return $response->getBody()->write(json_encode(array("token" => $_SESSION["token"])));
});
$app->get("/user/checkResetEmail/{email}", function (Request $request, Response $response, array $args)
@@ -339,8 +341,6 @@ $app->get("/user/resendEmail", function (Request $request, Response $response)
$app->get("/user/checkResetCode/{code}", function (Request $request, Response $response, array $args)
{
global $user;
if (empty($args["code"]))
{
// uh oh sent empty data
@@ -352,7 +352,35 @@ $app->get("/user/checkResetCode/{code}", function (Request $request, Response $r
// yay, code code matches
return $response;
}
return $response->withStatus(401);
});
$app->post("/user/changePassword", function (Request $request, Response $response)
{
global $user;
if (empty($_SESSION["resetToken"]) && empty($_SESSION["resetEmail"]))
{
// uh oh not authorized to change password
return $response->withStatus(401);
}
$data = $request->getParsedBody();
if (empty($data["password"]))
{
// uh oh sent empty data
return $response->withStatus(400);
}
if ($user->changePassword($_SESSION["resetEmail"], $data["password"]))
{
// yay, password changed
unset($_SESSION["resetToken"]);
unset($_SESSION["resetEmail"]);
return $response;
}
return $response->withStatus(500);
});
$app->run();