From 5213c33f2a4e40f2799da3e793c5137e234aed62 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 26 Apr 2021 08:21:51 +0200 Subject: [PATCH] back end update --- Backend/Controllers/Admin/AdminLogin.php | 2 +- Backend/Controllers/Admin/AdminSignup.php | 3 ++- Backend/Controllers/GameJam/UpdateGameJam.php | 2 +- Backend/Controllers/Group/GetGroup.php | 4 +++- Backend/Controllers/Group/ResetPassword.php | 3 +-- Backend/Controllers/Group/SigningUp.php | 3 --- Backend/Controllers/Group/UpdateGruop.php | 2 +- Backend/Controllers/Group/UpdatePassword.php | 2 +- .../Registration/GetRegistration.php | 19 +++++++++++++++++++ .../Registration/UpdateRegistration.php | 2 +- 10 files changed, 30 insertions(+), 12 deletions(-) diff --git a/Backend/Controllers/Admin/AdminLogin.php b/Backend/Controllers/Admin/AdminLogin.php index af3c392..9db9c47 100644 --- a/Backend/Controllers/Admin/AdminLogin.php +++ b/Backend/Controllers/Admin/AdminLogin.php @@ -18,7 +18,7 @@ if (isset($_POST['aLogin'])) { if (password_verify($password, $hashedPassword)) { $_SESSION['userName'] = $userName; $_SESSION['admin'] = true; - $_SESSION['success'] = "You are now logged in"; + //$_SESSION['success'] = "You are now logged in"; http_response_code(200); makeAdminLogin($userName); } else { diff --git a/Backend/Controllers/Admin/AdminSignup.php b/Backend/Controllers/Admin/AdminSignup.php index efb4f5b..2586b25 100644 --- a/Backend/Controllers/Admin/AdminSignup.php +++ b/Backend/Controllers/Admin/AdminSignup.php @@ -8,7 +8,8 @@ if (isAdmin()) { if (isset($_POST["newAdmin"])) { $admin = new AdminUser(); $admin->user_name = $_POST["newUsername"]; - $admin->password = $_POST["newPassword"]; + $admin->password = password_hash($_POST["newPassword"],PASSWORD_DEFAULT); + if ($admin->save()) { http_response_code(201); } else { diff --git a/Backend/Controllers/GameJam/UpdateGameJam.php b/Backend/Controllers/GameJam/UpdateGameJam.php index 643d0cd..deb2409 100644 --- a/Backend/Controllers/GameJam/UpdateGameJam.php +++ b/Backend/Controllers/GameJam/UpdateGameJam.php @@ -23,7 +23,7 @@ if (isAdmin()) { $gameJam->description = $_POST['description']; if ($gameJam->save()) { - http_response_code(201); + http_response_code(200); } else { http_response_code(500); } diff --git a/Backend/Controllers/Group/GetGroup.php b/Backend/Controllers/Group/GetGroup.php index 1f5ae47..837ecbd 100644 --- a/Backend/Controllers/Group/GetGroup.php +++ b/Backend/Controllers/Group/GetGroup.php @@ -15,4 +15,6 @@ if (isset($_GET["groupId"])) { header("Access-Control-Allow-Methods: GET"); header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept"); header('Content-Type: application/json;charset=UTF-8'); -echo json_encode(array('data' => $groups->jsonSerialize())); \ No newline at end of file +echo json_encode(array('data' => $groups->jsonSerialize())); + + diff --git a/Backend/Controllers/Group/ResetPassword.php b/Backend/Controllers/Group/ResetPassword.php index 21a2647..624c126 100644 --- a/Backend/Controllers/Group/ResetPassword.php +++ b/Backend/Controllers/Group/ResetPassword.php @@ -10,11 +10,10 @@ if (isAdmin()) { $password = Password::firstWhere("group_id", $_POST['groupId']); if ($password) { $password->password = password_hash($_POST['newPassword'], PASSWORD_DEFAULT); - echo $password; if (!$password->save()) { http_response_code(500); } else { - http_response_code(201); + http_response_code(200); } } else { http_response_code(400); diff --git a/Backend/Controllers/Group/SigningUp.php b/Backend/Controllers/Group/SigningUp.php index 0e6a8a1..f2d9bb1 100644 --- a/Backend/Controllers/Group/SigningUp.php +++ b/Backend/Controllers/Group/SigningUp.php @@ -8,9 +8,6 @@ use Backend\Models\Password; use Backend\Models\GameJam; use Illuminate\Support\Str; -$groupName = ""; -$errors = array(); - if (isset($_POST['regGroup'])) { diff --git a/Backend/Controllers/Group/UpdateGruop.php b/Backend/Controllers/Group/UpdateGruop.php index 20887a5..63bff66 100644 --- a/Backend/Controllers/Group/UpdateGruop.php +++ b/Backend/Controllers/Group/UpdateGruop.php @@ -11,7 +11,7 @@ if (isLogin()) { if (!$group->save()) { http_response_code(500); } else { - http_response_code(201); + http_response_code(200); } } else { http_response_code(400); diff --git a/Backend/Controllers/Group/UpdatePassword.php b/Backend/Controllers/Group/UpdatePassword.php index decd555..b7ca68d 100644 --- a/Backend/Controllers/Group/UpdatePassword.php +++ b/Backend/Controllers/Group/UpdatePassword.php @@ -12,7 +12,7 @@ if (isLogin()) { if (!$password->save()) { http_response_code(500); } else { - http_response_code(201); + http_response_code(200); } } else { http_response_code(400); diff --git a/Backend/Controllers/Registration/GetRegistration.php b/Backend/Controllers/Registration/GetRegistration.php index b3d9bbc..e43a94e 100644 --- a/Backend/Controllers/Registration/GetRegistration.php +++ b/Backend/Controllers/Registration/GetRegistration.php @@ -1 +1,20 @@ get(); +} elseif (isset($_GET["gameJamId"])){ + $regs = Registration::where("game_jam_id", $_GET["gameJamId"])->get(); +}elseif (isset($_GET["gameDataId"])){ + $regs = Registration::where("game_data_id", $_GET["gameDataId"])->get(); +}else{ + $regs = Registration::all(); +} +header("Access-Control-Allow-Methods: GET"); +header("Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept"); +header('Content-Type: application/json;charset=UTF-8'); +echo json_encode(array('data' => $regs->jsonSerialize())); \ No newline at end of file diff --git a/Backend/Controllers/Registration/UpdateRegistration.php b/Backend/Controllers/Registration/UpdateRegistration.php index 4c2451f..47afce5 100644 --- a/Backend/Controllers/Registration/UpdateRegistration.php +++ b/Backend/Controllers/Registration/UpdateRegistration.php @@ -6,7 +6,7 @@ use Backend\Models\Registration; if(isLogin()){ if(isset($_POST['updateReg'])){ - if($reg = Registration::where("group_id", $_POST["groupId"])->where("game_jam_id", $_POST["gameJamId"])->first()){ + if($reg = Registration::find($_POST["registrationId"])->where("group_id", groupViaToken($_SESSION['token'])->id)->first()){ $reg->group_amount = $_POST["groupAmount"]; if($reg->save()){ http_response_code(200);