From fbdf9e675c871ad912f62f95d84e101ac595b1fe Mon Sep 17 00:00:00 2001 From: RundelhausCode Date: Tue, 9 Mar 2021 10:45:05 +0100 Subject: [PATCH 1/2] folder restrokteer --- .gitignore | 2 +- Backend/Controllers/Admin/AdminLogin.php | 36 +++++++++++++++++++ Backend/Controllers/Admin/NewGameJam.php | 21 +++++++++++ Backend/Controllers/Admin/ResetPassword.php | 5 ++- Backend/Controllers/Admin/UpdateGameJam.php | 27 ++++++++++++++ Backend/Controllers/GameJam/GetGameJam.php | 1 + Backend/Controllers/{User => Group}/Login.php | 0 .../Controllers/{User => Group}/SigningUp.php | 8 +++-- Backend/Controllers/Group/UpdateGruop.php | 15 ++++++++ .../Controllers/{User => Group}/logout.php | 0 composer.json | 3 +- 11 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 Backend/Controllers/Admin/AdminLogin.php create mode 100644 Backend/Controllers/Admin/NewGameJam.php create mode 100644 Backend/Controllers/Admin/UpdateGameJam.php create mode 100644 Backend/Controllers/GameJam/GetGameJam.php rename Backend/Controllers/{User => Group}/Login.php (100%) rename Backend/Controllers/{User => Group}/SigningUp.php (81%) create mode 100644 Backend/Controllers/Group/UpdateGruop.php rename Backend/Controllers/{User => Group}/logout.php (100%) diff --git a/.gitignore b/.gitignore index 8c4bee2..84b4ab0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 -# User-specific stuff +# Group-specific stuff .idea/**/workspace.xml .idea/**/tasks.xml .idea/**/usage.statistics.xml diff --git a/Backend/Controllers/Admin/AdminLogin.php b/Backend/Controllers/Admin/AdminLogin.php new file mode 100644 index 0000000..e7e48eb --- /dev/null +++ b/Backend/Controllers/Admin/AdminLogin.php @@ -0,0 +1,36 @@ +password; + if(password_verify($password, $hashedPassword )){ + $_SESSION['userName'] = $userName; + $_SESSION['Admin'] = true; + $_SESSION['userId'] = $user->id; + $_SESSION['success'] = "You are now logged in"; + header('location: ../Frontend/index.php?login=success'); + }else{ + session_destroy(); + header('location: ../Frontend/index.php?login=failed?reason=password'); + } + + + } + else{ + session_destroy(); + header('location: ../Frontend/index.php?login=failed?reason=username'); + } + + +} \ No newline at end of file diff --git a/Backend/Controllers/Admin/NewGameJam.php b/Backend/Controllers/Admin/NewGameJam.php new file mode 100644 index 0000000..e9ce6fd --- /dev/null +++ b/Backend/Controllers/Admin/NewGameJam.php @@ -0,0 +1,21 @@ +name = $_POST["gameJam_name"]; + $gameJam->start_time = $_POST["start_time"]; + $gameJam->end_time = $_POST["end_time"]; + $gameJam->description = $_POST["description"]; + + if($gameJam->save()){ + + } + else{ + + } + } +} \ No newline at end of file diff --git a/Backend/Controllers/Admin/ResetPassword.php b/Backend/Controllers/Admin/ResetPassword.php index d931420..1513f73 100644 --- a/Backend/Controllers/Admin/ResetPassword.php +++ b/Backend/Controllers/Admin/ResetPassword.php @@ -9,7 +9,10 @@ if(isset($_SESSION['Admin'])){ if(isset($_POST['RestPassword'])){ $group = Group::find($_POST['groupId']); if($group){ - $group->password->password = password_hash("Aa123456&", PASSWORD_DEFAULT); + $group->password->password = password_hash($_POST['NewPassword'], PASSWORD_DEFAULT); + if($group->save()){ + + } } } } \ No newline at end of file diff --git a/Backend/Controllers/Admin/UpdateGameJam.php b/Backend/Controllers/Admin/UpdateGameJam.php new file mode 100644 index 0000000..ca0f843 --- /dev/null +++ b/Backend/Controllers/Admin/UpdateGameJam.php @@ -0,0 +1,27 @@ +name = $_POST['name']; + + $gameJam->start_time = $_POST['start_time']; + + $gameJam->end_time = $_POST['start_time']; + + if (!empty($_POST['key_word'])) { + $gameJam->key_word = $_POST['key_word']; + } + + $gameJam->description = $_POST['description']; + if ($gameJam->save()) { + + } + } + } + +} diff --git a/Backend/Controllers/GameJam/GetGameJam.php b/Backend/Controllers/GameJam/GetGameJam.php new file mode 100644 index 0000000..b3d9bbc --- /dev/null +++ b/Backend/Controllers/GameJam/GetGameJam.php @@ -0,0 +1 @@ +password = password_hash($_POST['password'] ,PASSWORD_DEFAULT); + $token = OAuthProvider::generateToken(100); + + $password->remember_token = $token; + if(!$password->save()){ return; } $_SESSION['groupName'] = $groupName; - $_SESSION['groupId'] = $group->id; + $_SESSION['token'] = $token; $_SESSION['success'] = "You are now logged in"; - header('location: index.php'); + header('location: ../../../Frontend/index.php'); } diff --git a/Backend/Controllers/Group/UpdateGruop.php b/Backend/Controllers/Group/UpdateGruop.php new file mode 100644 index 0000000..9726876 --- /dev/null +++ b/Backend/Controllers/Group/UpdateGruop.php @@ -0,0 +1,15 @@ + Date: Tue, 9 Mar 2021 13:16:34 +0100 Subject: [PATCH 2/2] Token for groups --- Backend/Controllers/Group/Login.php | 23 +++++++++++++++++------ Backend/Controllers/Group/SigningUp.php | 3 ++- Backend/Controllers/Group/UpdateGruop.php | 17 +++++++++++++---- composer.json | 1 - composer.lock | 10 +++++----- 5 files changed, 37 insertions(+), 17 deletions(-) diff --git a/Backend/Controllers/Group/Login.php b/Backend/Controllers/Group/Login.php index b5feeb5..672cd53 100644 --- a/Backend/Controllers/Group/Login.php +++ b/Backend/Controllers/Group/Login.php @@ -4,6 +4,7 @@ require "../../../bootstrap.php"; use Backend\Models\Group; use Backend\Models\Password; +use Illuminate\Support\Str; //Start the php session session_start(); @@ -17,20 +18,30 @@ if(isset($_POST['login'])){ if($group){ $hashedPassword = $group->password->password; if(password_verify($password, $hashedPassword )){ - $_SESSION['groupName'] = $groupName; - $_SESSION['groupId'] = $group->id; - $_SESSION['success'] = "You are now logged in"; - header('location: ../Frontend/index.php?login=success'); + $token = Str::random(100); + $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"; + header('location: ../../../Frontend/index.php?login=success'); + } + else{ + session_destroy(); + header('location: ../../../Frontend/index.php?login=failed&?reason=token'); + } + }else{ session_destroy(); - header('location: ../Frontend/index.php?login=failed?reason=password'); + header('location: ../../../Frontend/index.php?login=failed&?reason=password'); } } else{ session_destroy(); - header('location: ../Frontend/index.php?login=failed?reason=group'); + header('location: ../../../Frontend/index.php?login=failed&?reason=group'); } diff --git a/Backend/Controllers/Group/SigningUp.php b/Backend/Controllers/Group/SigningUp.php index 78be7e9..e33e527 100644 --- a/Backend/Controllers/Group/SigningUp.php +++ b/Backend/Controllers/Group/SigningUp.php @@ -5,6 +5,7 @@ require "../../../bootstrap.php"; use Backend\Models\Group; use Backend\Models\Password; use Backend\Models\GameJam; +use Illuminate\Support\Str; session_start(); @@ -33,7 +34,7 @@ if(isset($_POST['reg_group'])){ $password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT); - $token = OAuthProvider::generateToken(100); + $token = Str::random(100); $password->remember_token = $token; diff --git a/Backend/Controllers/Group/UpdateGruop.php b/Backend/Controllers/Group/UpdateGruop.php index 9726876..84e763a 100644 --- a/Backend/Controllers/Group/UpdateGruop.php +++ b/Backend/Controllers/Group/UpdateGruop.php @@ -2,14 +2,23 @@ require "../../../bootstrap.php"; use Backend\Models\Group; -use Backend\Models\Password; session_start(); -if(isset($_SESSION['groupId'])){ if (isset($_POST['updateGroup'])) { - $_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->save(); + } + } + + + + } -} + diff --git a/composer.json b/composer.json index 7d694d4..ab3aec1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "require": { "illuminate/database": "^8.30", - "ext-oauth": "*" }, "autoload": { "classmap": [ diff --git a/composer.lock b/composer.lock index da1aef9..428ee73 100644 --- a/composer.lock +++ b/composer.lock @@ -438,16 +438,16 @@ }, { "name": "nesbot/carbon", - "version": "2.45.1", + "version": "2.46.0", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "528783b188bdb853eb21239b1722831e0f000a8d" + "reference": "2fd2c4a77d58a4e95234c8a61c5df1f157a91bf4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/528783b188bdb853eb21239b1722831e0f000a8d", - "reference": "528783b188bdb853eb21239b1722831e0f000a8d", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/2fd2c4a77d58a4e95234c8a61c5df1f157a91bf4", + "reference": "2fd2c4a77d58a4e95234c8a61c5df1f157a91bf4", "shasum": "" }, "require": { @@ -527,7 +527,7 @@ "type": "tidelift" } ], - "time": "2021-02-11T18:30:17+00:00" + "time": "2021-02-24T17:30:44+00:00" }, { "name": "psr/container",