diff --git a/.gitignore b/.gitignore index 84b4ab0..e102757 100644 --- a/.gitignore +++ b/.gitignore @@ -109,3 +109,5 @@ composer.phar /Backend/Database/test.db /Backend/Games/ /Frontend/images/ +/Test/ +/Test/ diff --git a/Backend/Controllers/Admin/Admin.php b/Backend/Controllers/Admin/Admin.php new file mode 100644 index 0000000..6b54cc6 --- /dev/null +++ b/Backend/Controllers/Admin/Admin.php @@ -0,0 +1,9 @@ +password; if(password_verify($password, $hashedPassword )){ $_SESSION['userName'] = $userName; - $_SESSION['Admin'] = true; - $_SESSION['userId'] = $user->id; + $_SESSION['admin'] = true; $_SESSION['success'] = "You are now logged in"; header('location: ../Frontend/index.php?login=success'); }else{ diff --git a/Backend/Controllers/Admin/NewGameJam.php b/Backend/Controllers/Admin/NewGameJam.php index e9ce6fd..8735cdc 100644 --- a/Backend/Controllers/Admin/NewGameJam.php +++ b/Backend/Controllers/Admin/NewGameJam.php @@ -1,14 +1,19 @@ name = $_POST["gameJam_name"]; - $gameJam->start_time = $_POST["start_time"]; - $gameJam->end_time = $_POST["end_time"]; + $gameJam->name = $_POST["gameJamName"]; + $gameJam->start_time = $_POST["startDate"]."T".$_POST["startTime"]; + $gameJam->end_time = $_POST["endDate"]."T".$_POST["endTime"]; $gameJam->description = $_POST["description"]; if($gameJam->save()){ diff --git a/Backend/Controllers/Admin/ResetPassword.php b/Backend/Controllers/Admin/ResetPassword.php index 1513f73..7765765 100644 --- a/Backend/Controllers/Admin/ResetPassword.php +++ b/Backend/Controllers/Admin/ResetPassword.php @@ -1,15 +1,16 @@ password->password = password_hash($_POST['NewPassword'], PASSWORD_DEFAULT); + $group->password->password = password_hash($_POST['newPassword'], PASSWORD_DEFAULT); if($group->save()){ } diff --git a/Backend/Controllers/Admin/UpdateGameJam.php b/Backend/Controllers/Admin/UpdateGameJam.php index ca0f843..60fd307 100644 --- a/Backend/Controllers/Admin/UpdateGameJam.php +++ b/Backend/Controllers/Admin/UpdateGameJam.php @@ -1,20 +1,21 @@ name = $_POST['name']; - $gameJam->start_time = $_POST['start_time']; + $gameJam->start_time = $_POST["startDate"]."T".$_POST["startTime"]; - $gameJam->end_time = $_POST['start_time']; + $gameJam->end_time = $_POST["endDate"]."T".$_POST["endTime"]; if (!empty($_POST['key_word'])) { - $gameJam->key_word = $_POST['key_word']; + $gameJam->key_word = $_POST['keyWord']; } $gameJam->description = $_POST['description']; diff --git a/Backend/Controllers/FileHandler/upload.php b/Backend/Controllers/FileHandler/upload.php index 281c3ea..1b77154 100644 --- a/Backend/Controllers/FileHandler/upload.php +++ b/Backend/Controllers/FileHandler/upload.php @@ -10,7 +10,7 @@ $isImages = false; session_start(); -if(isset($_SESSION['token'])){ +if(isLogin()){ $group = groupViaToken($_SESSION['token']); diff --git a/Backend/Controllers/Group/Group.php b/Backend/Controllers/Group/Group.php index 684609e..73b23af 100644 --- a/Backend/Controllers/Group/Group.php +++ b/Backend/Controllers/Group/Group.php @@ -6,10 +6,11 @@ use Backend\Models\Password; /** * @param string $token - * @return Group; + * @return Group|null ; */ -function groupViaToken(string $token){ +function groupViaToken(string $token): ?Group +{ if($password = Password::firstWhere('remember_token', $token)){ return Group::find($password->group_id); @@ -17,6 +18,28 @@ function groupViaToken(string $token){ return null; } +/** + * @return bool + */ function isLogin(){ return isset($_SESSION["token"]); +} + +/** + * @param string $password1 + * @param string $password2 + * @return bool + */ +function passwordValidate(string $password1, string $password2 ){ + if($password1 === $password2){ + $uppercase = preg_match('@[A-Z]@', $password1); + $lowercase = preg_match('@[a-z]@', $password1); + $number = preg_match('@[0-9]@', $password1); + $specialChars = preg_match('@[^\w]@', $password1); + + if(!$uppercase || !$lowercase || !$number || !$specialChars || (strlen($password1) < 8 && strlen($password1) > 255)) { + return true; + } + } + else false; } \ No newline at end of file diff --git a/Backend/Controllers/Group/Login.php b/Backend/Controllers/Group/Login.php index 672cd53..d261379 100644 --- a/Backend/Controllers/Group/Login.php +++ b/Backend/Controllers/Group/Login.php @@ -19,9 +19,9 @@ if(isset($_POST['login'])){ $hashedPassword = $group->password->password; if(password_verify($password, $hashedPassword )){ $token = Str::random(100); - $grouppassword = Password::firstWhere('group_id', $group->id); - $grouppassword->remember_token = $token; - if($grouppassword->save()){ + $groupPassword = Password::firstWhere('group_id', $group->id); + $groupPassword->remember_token = $token; + if($groupPassword->save()){ $_SESSION['groupName'] = $groupName; $_SESSION['token'] = $token; $_SESSION['success'] = "You are now logged in"; diff --git a/Backend/Controllers/Group/SigningUp.php b/Backend/Controllers/Group/SigningUp.php index e33e527..1807dcc 100644 --- a/Backend/Controllers/Group/SigningUp.php +++ b/Backend/Controllers/Group/SigningUp.php @@ -12,38 +12,38 @@ session_start(); $groupName = ""; $errors = array(); -if(isset($_POST['reg_group'])){ +if(isset($_POST['regGroup'])){ + if(passwordValidate($pass = $_POST['password1'], $_POST['password2'])){ + $group = new Group(); + $group->gameJam()->associate(GameJam::find($_POST['gameJamId'])); - $group = new Group(); + $group->group_name = $groupName = $_POST['groupName']; - $group->gameJam()->associate(GameJam::find($_POST['gameJamId'])); + $group->group_amount = $_POST['groupAmount']; - $group->group_name = $groupName = $_POST['groupName']; + if(!$group->save()){ + return; + } + $password = New Password(); - $group->group_amount = $_POST['groupAmount']; + $password->group()->associate($group); - if(!$group->save()){ - return; + $password->password = password_hash($pass ,PASSWORD_DEFAULT); + + $token = Str::random(100); + + $password->remember_token = $token; + + if(!$password->save()){ + return; + } + + $_SESSION['groupName'] = $groupName; + $_SESSION['token'] = $token; + $_SESSION['success'] = "You are now logged in"; + header('location: ../../../Frontend/index.php'); } - $password = New Password(); - - $password->group()->associate($group); - - $password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT); - - $token = Str::random(100); - - $password->remember_token = $token; - - if(!$password->save()){ - return; - } - - $_SESSION['groupName'] = $groupName; - $_SESSION['token'] = $token; - $_SESSION['success'] = "You are now logged in"; - header('location: ../../../Frontend/index.php'); } diff --git a/Backend/Controllers/Group/UpdateGruop.php b/Backend/Controllers/Group/UpdateGruop.php index 84e763a..f0cb3bf 100644 --- a/Backend/Controllers/Group/UpdateGruop.php +++ b/Backend/Controllers/Group/UpdateGruop.php @@ -7,9 +7,9 @@ session_start(); if (isset($_POST['updateGroup'])) { if($group = Group::find($_POST['groupId'])){ if ($group->password->remember_token === $_SESSION['token']){ - $group->group_name = $_POST['group_name']; - $group->group_amount = $_POST['group_amount']; - $group->game_jam_id = $_POST['game_jam_id']; + $group->group_name = $_POST['groupName']; + $group->group_amount = $_POST['groupAmount']; + $group->game_jam_id = $_POST['gameJamId']; $group->save(); } } diff --git a/Backend/Controllers/Group/UpdatePassword.php b/Backend/Controllers/Group/UpdatePassword.php new file mode 100644 index 0000000..6c5bd5f --- /dev/null +++ b/Backend/Controllers/Group/UpdatePassword.php @@ -0,0 +1,14 @@ +id); + if(passwordValidate($pass = $_POST['password1'], $_POST['password2'])){ + $password = password_hash($pass,PASSWORD_DEFAULT); + $password->save(); + } + +} diff --git a/Backend/Controllers/Group/logout.php b/Backend/Controllers/Group/logout.php index 4cc95b7..ac9b642 100644 --- a/Backend/Controllers/Group/logout.php +++ b/Backend/Controllers/Group/logout.php @@ -1,3 +1,5 @@