password reset, admin upadte and Camel case update

This commit is contained in:
RundelhausCode 2021-03-11 09:28:30 +01:00
parent 246cfad08a
commit a65e9ceec8
16 changed files with 117 additions and 60 deletions

2
.gitignore vendored
View File

@ -109,3 +109,5 @@ composer.phar
/Backend/Database/test.db /Backend/Database/test.db
/Backend/Games/ /Backend/Games/
/Frontend/images/ /Frontend/images/
/Test/
/Test/

View File

@ -0,0 +1,9 @@
<?php
/**
* @return bool
*/
function isAdmin(){
session_start();
return isset($_SESSION['admin']);
}

View File

@ -1,12 +1,13 @@
<?php <?php
require "../../../bootstrap.php"; require_once "../../../bootstrap.php";
require_once "Admin.php";
use Backend\Models\AdminUser; use Backend\Models\AdminUser;
//Start the php session //Start the php session
session_start(); session_start();
if(isset($_POST['ALogin'])){ if(isset($_POST['aLogin'])){
$userName = $_POST["userName"]; $userName = $_POST["userName"];
$password = $_POST["password"]; $password = $_POST["password"];
@ -16,8 +17,7 @@ if(isset($_POST['ALogin'])){
$hashedPassword = $user->password; $hashedPassword = $user->password;
if(password_verify($password, $hashedPassword )){ if(password_verify($password, $hashedPassword )){
$_SESSION['userName'] = $userName; $_SESSION['userName'] = $userName;
$_SESSION['Admin'] = true; $_SESSION['admin'] = true;
$_SESSION['userId'] = $user->id;
$_SESSION['success'] = "You are now logged in"; $_SESSION['success'] = "You are now logged in";
header('location: ../Frontend/index.php?login=success'); header('location: ../Frontend/index.php?login=success');
}else{ }else{

View File

@ -1,14 +1,19 @@
<?php <?php
require "../../../bootstrap.php"; require_once "../../../bootstrap.php";
require_once "Admin.php";
use Backend\Models\GameJam; use Backend\Models\GameJam;
if(isset($_SESSION['Admin'])){ var_dump($_POST);
if(isset($_POST['NewGameJam'])){
session_start();
if(isAdmin()){
if(isset($_POST['newGameJam'])){
$gameJam = New GameJam(); $gameJam = New GameJam();
$gameJam->name = $_POST["gameJam_name"]; $gameJam->name = $_POST["gameJamName"];
$gameJam->start_time = $_POST["start_time"]; $gameJam->start_time = $_POST["startDate"]."T".$_POST["startTime"];
$gameJam->end_time = $_POST["end_time"]; $gameJam->end_time = $_POST["endDate"]."T".$_POST["endTime"];
$gameJam->description = $_POST["description"]; $gameJam->description = $_POST["description"];
if($gameJam->save()){ if($gameJam->save()){

View File

@ -1,15 +1,16 @@
<?php <?php
require "../../../bootstrap.php"; require_once "../../../bootstrap.php";
require_once "Admin.php";
use Backend\Models\Group; use Backend\Models\Group;
use Backend\Models\Password; use Backend\Models\Password;
session_start(); session_start();
if(isset($_SESSION['Admin'])){ if(isAdmin()){
if(isset($_POST['RestPassword'])){ if(isset($_POST['restPassword'])){
$group = Group::find($_POST['groupId']); $group = Group::find($_POST['groupId']);
if($group){ if($group){
$group->password->password = password_hash($_POST['NewPassword'], PASSWORD_DEFAULT); $group->password->password = password_hash($_POST['newPassword'], PASSWORD_DEFAULT);
if($group->save()){ if($group->save()){
} }

View File

@ -1,20 +1,21 @@
<?php <?php
require "../../../bootstrap.php"; require_once "../../../bootstrap.php";
require_once "Admin.php";
use Backend\Models\GameJam; use Backend\Models\GameJam;
if(isset($_SESSION['Admin'])){ if(isAdmin()){
if(isset($_POST['UpdateGameJam'])) { if(isset($_POST['updateGameJam'])) {
$gameJam = GameJam::find($_POST['game_jam_id']); $gameJam = GameJam::find($_POST['gameJamId']);
if($gameJam){ if($gameJam){
$gameJam->name = $_POST['name']; $gameJam->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'])) { if (!empty($_POST['key_word'])) {
$gameJam->key_word = $_POST['key_word']; $gameJam->key_word = $_POST['keyWord'];
} }
$gameJam->description = $_POST['description']; $gameJam->description = $_POST['description'];

View File

@ -10,7 +10,7 @@ $isImages = false;
session_start(); session_start();
if(isset($_SESSION['token'])){ if(isLogin()){
$group = groupViaToken($_SESSION['token']); $group = groupViaToken($_SESSION['token']);

View File

@ -6,10 +6,11 @@ use Backend\Models\Password;
/** /**
* @param string $token * @param string $token
* @return Group; * @return Group|null ;
*/ */
function groupViaToken(string $token){ function groupViaToken(string $token): ?Group
{
if($password = Password::firstWhere('remember_token', $token)){ if($password = Password::firstWhere('remember_token', $token)){
return Group::find($password->group_id); return Group::find($password->group_id);
@ -17,6 +18,28 @@ function groupViaToken(string $token){
return null; return null;
} }
/**
* @return bool
*/
function isLogin(){ function isLogin(){
return isset($_SESSION["token"]); 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;
} }

View File

@ -19,9 +19,9 @@ if(isset($_POST['login'])){
$hashedPassword = $group->password->password; $hashedPassword = $group->password->password;
if(password_verify($password, $hashedPassword )){ if(password_verify($password, $hashedPassword )){
$token = Str::random(100); $token = Str::random(100);
$grouppassword = Password::firstWhere('group_id', $group->id); $groupPassword = Password::firstWhere('group_id', $group->id);
$grouppassword->remember_token = $token; $groupPassword->remember_token = $token;
if($grouppassword->save()){ if($groupPassword->save()){
$_SESSION['groupName'] = $groupName; $_SESSION['groupName'] = $groupName;
$_SESSION['token'] = $token; $_SESSION['token'] = $token;
$_SESSION['success'] = "You are now logged in"; $_SESSION['success'] = "You are now logged in";

View File

@ -12,38 +12,38 @@ session_start();
$groupName = ""; $groupName = "";
$errors = array(); $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()){ $password->password = password_hash($pass ,PASSWORD_DEFAULT);
return;
$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');
} }

View File

@ -7,9 +7,9 @@ session_start();
if (isset($_POST['updateGroup'])) { if (isset($_POST['updateGroup'])) {
if($group = Group::find($_POST['groupId'])){ if($group = Group::find($_POST['groupId'])){
if ($group->password->remember_token === $_SESSION['token']){ if ($group->password->remember_token === $_SESSION['token']){
$group->group_name = $_POST['group_name']; $group->group_name = $_POST['groupName'];
$group->group_amount = $_POST['group_amount']; $group->group_amount = $_POST['groupAmount'];
$group->game_jam_id = $_POST['game_jam_id']; $group->game_jam_id = $_POST['gameJamId'];
$group->save(); $group->save();
} }
} }

View File

@ -0,0 +1,14 @@
<?php
require_once "../../../bootstrap.php";
require_once "Group.php";
use Backend\Models\Password;
if(isset($_SESSION['token'])){
if(isset($_POST['updatePassword']))
$password = Password::firstWhere("group_id", groupViaToken($_SESSION["token"])->id);
if(passwordValidate($pass = $_POST['password1'], $_POST['password2'])){
$password = password_hash($pass,PASSWORD_DEFAULT);
$password->save();
}
}

View File

@ -1,3 +1,5 @@
<?php <?php
session_start();
session_destroy(); session_destroy();

View File

@ -5,7 +5,7 @@ use Backend\Models\Vote;
require "../../../bootstrap.php"; require "../../../bootstrap.php";
if(isset($_POST['1vote_for'])){ if(isset($_POST['1Vote'])){
require "VoteChecking.php"; require "VoteChecking.php";
$vote = new Vote(); $vote = new Vote();

View File

@ -5,7 +5,7 @@ use Backend\Models\Vote;
require "../../../bootstrap.php"; require "../../../bootstrap.php";
if(isset($_POST['321vote_for'])){ if(isset($_POST['321Vote'])){
require "VoteChecking.php"; require "VoteChecking.php";
//give 1 point //give 1 point

View File

@ -1,10 +1,10 @@
<?php <?php
$votes = array(); $votes = array();
if(isset($_COOKIE["Voting_reg"])) { if(isset($_COOKIE["votingReg"])) {
$votes = unserialize($_COOKIE["Voting_reg"]); $votes = unserialize($_COOKIE["votingReg"]);
foreach ($votes as $vote){ foreach ($votes as $vote){
if($_POST['gameJamId'] === $vote) return; if($_POST['gameJamId'] === $vote) return;
} }
} }
array_push($votes,$_POST['gameJamId']); array_push($votes,$_POST['gameJamId']);
setcookie("Voting_reg", serialize($votes), time() + 86400, "/"); setcookie("VotingReg", serialize($votes), time() + 86400, "/");