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/Games/
/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
require "../../../bootstrap.php";
require_once "../../../bootstrap.php";
require_once "Admin.php";
use Backend\Models\AdminUser;
//Start the php session
session_start();
if(isset($_POST['ALogin'])){
if(isset($_POST['aLogin'])){
$userName = $_POST["userName"];
$password = $_POST["password"];
@ -16,8 +17,7 @@ if(isset($_POST['ALogin'])){
$hashedPassword = $user->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{

View File

@ -1,14 +1,19 @@
<?php
require "../../../bootstrap.php";
require_once "../../../bootstrap.php";
require_once "Admin.php";
use Backend\Models\GameJam;
if(isset($_SESSION['Admin'])){
if(isset($_POST['NewGameJam'])){
var_dump($_POST);
session_start();
if(isAdmin()){
if(isset($_POST['newGameJam'])){
$gameJam = New GameJam();
$gameJam->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()){

View File

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

View File

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

View File

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

View File

@ -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;
}

View File

@ -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";

View File

@ -12,11 +12,10 @@ 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']));
@ -32,7 +31,7 @@ if(isset($_POST['reg_group'])){
$password->group()->associate($group);
$password->password = password_hash($_POST['password'] ,PASSWORD_DEFAULT);
$password->password = password_hash($pass ,PASSWORD_DEFAULT);
$token = Str::random(100);
@ -46,4 +45,5 @@ if(isset($_POST['reg_group'])){
$_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($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();
}
}

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
session_start();
session_destroy();

View File

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

View File

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

View File

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