Login fix

This commit is contained in:
RundelhausCode 2021-03-12 11:10:14 +01:00
parent a31ed44bdd
commit c6e002d464
12 changed files with 43 additions and 35 deletions

View File

@ -2,7 +2,8 @@
/** /**
* @return bool * @return bool
*/ */
function isAdmin(){ function isAdmin(): bool
{
session_start(); session_start();
return isset($_SESSION['admin']); return isset($_SESSION['admin']);
} }

View File

@ -19,17 +19,17 @@ if(isset($_POST['aLogin'])){
$_SESSION['userName'] = $userName; $_SESSION['userName'] = $userName;
$_SESSION['admin'] = true; $_SESSION['admin'] = true;
$_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{
session_destroy(); session_destroy();
header('location: ../Frontend/index.php?login=failed?reason=password'); header('location: ../../../Frontend/index.php?login=failed?reason=password');
} }
} }
else{ else{
session_destroy(); session_destroy();
header('location: ../Frontend/index.php?login=failed?reason=username'); header('location: ../../../Frontend/index.php?login=failed?reason=username');
} }

View File

@ -2,14 +2,16 @@
/** /**
* @param string $gameFileName * @param string $gameFileName
* @param string $gameFileTmp * @param string $gameFileTmp
* @return string * @return string|null
*/ */
function ZipFileHandler(string $gameFileName, string $gameFileTmp){ function ZipFileHandler(string $gameFileName, string $gameFileTmp): ?string
{
$fileExtGame = explode('.', $gameFileName); $fileExtGame = explode('.', $gameFileName);
$fileActualExtGame = strtolower(end($fileExtGame)); $fileActualExtGame = strtolower(end($fileExtGame));
$allowedFileTypeGame = array('zip'); $allowedFileTypeGame = array('zip');
if(in_array($fileActualExtGame,$allowedFileTypeGame)){ if(in_array($fileActualExtGame,$allowedFileTypeGame)){
$gameFileNewName = uniqid("", true). "." . $fileActualExtGame; $gameFileNewName = uniqid("", true). "." . $fileActualExtGame;
if(empty($gameFileName)){ if(empty($gameFileName)){
@ -19,15 +21,19 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp){
rename($gameFileTmp,"../../Games/".$gameFileNewName); rename($gameFileTmp,"../../Games/".$gameFileNewName);
return $gameFileNewName; return $gameFileNewName;
} }
return NULL; return NULL;
} }
/** /**
* @param string $thumbnailFileName * @param string $thumbnailFileName
* @param string $thumbnailFileTmp * @param string $thumbnailFileTmp
* @return string * @return string|null
*/ */
function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp): ?string
{
$fileExtThumb = explode('.', $thumbnailFileName); $fileExtThumb = explode('.', $thumbnailFileName);
$fileActualExtThumb = strtolower(end($fileExtThumb)); $fileActualExtThumb = strtolower(end($fileExtThumb));

View File

@ -1,11 +1,11 @@
<?php <?php
require_once "../../../bootstrap.php"; require_once "../../../bootstrap.php";
require_once "Admin.php"; require_once "../Admin/Admin.php";
use Backend\Models\GameJam; use Backend\Models\GameJam;
var_dump($_POST); //var_dump($_POST);
session_start(); //session_start();
if(isAdmin()){ if(isAdmin()){
if(isset($_POST['newGameJam'])){ if(isset($_POST['newGameJam'])){

View File

@ -1,6 +1,6 @@
<?php <?php
require_once "../../../bootstrap.php"; require_once "../../../bootstrap.php";
require_once "Admin.php"; require_once "../Admin/Admin.php";
use Backend\Models\GameJam; use Backend\Models\GameJam;
if(isAdmin()){ if(isAdmin()){
@ -8,14 +8,16 @@ if(isAdmin()){
$gameJam = GameJam::find($_POST['gameJamId']); $gameJam = GameJam::find($_POST['gameJamId']);
if($gameJam){ if($gameJam){
$gameJam->name = $_POST['name']; $gameJam->name = $_POST['gameJamName'];
$gameJam->start_time = $_POST["startDate"]."T".$_POST["startTime"]; $gameJam->start_time = $_POST["startDate"]."T".$_POST["startTime"];
$gameJam->end_time = $_POST["endDate"]."T".$_POST["endTime"]; $gameJam->end_time = $_POST["endDate"]."T".$_POST["endTime"];
if (!empty($_POST['key_word'])) { if (!empty($_POST['keyWord'])) {
$gameJam->key_word = $_POST['keyWord']; $gameJam->key_word = $_POST['keyWord'];
}else{
$gameJam->key_word = null;
} }
$gameJam->description = $_POST['description']; $gameJam->description = $_POST['description'];

View File

@ -1,5 +1,5 @@
<?php <?php
require_once "../../../bootstrap.php"; require_once (realpath(dirname(__FILE__) ."/../../../bootstrap.php"));
use Backend\Models\Group; use Backend\Models\Group;
use Backend\Models\Password; use Backend\Models\Password;
@ -22,25 +22,24 @@ function groupViaToken(string $token): ?Group
/** /**
* @return bool * @return bool
*/ */
function isLogin(){ function isLogin(): bool
{
return isset($_SESSION["token"]); return isset($_SESSION["token"]);
} }
/** /**
* @param string $password1 * @param string $password1
* @param string $password2
* @return bool * @return bool
*/ */
function passwordValidate(string $password1, string $password2 ){ function passwordValidate(string $password1): bool
if($password1 === $password2){ {
$uppercase = preg_match('@[A-Z]@', $password1); $uppercase = preg_match('@[A-Z]@', $password1);
$lowercase = preg_match('@[a-z]@', $password1); $lowercase = preg_match('@[a-z]@', $password1);
$number = preg_match('@[0-9]@', $password1); $number = preg_match('@[0-9]@', $password1);
$specialChars = preg_match('@[^\w]@', $password1); $specialChars = preg_match('@[^\w]@', $password1);
if(!$uppercase || !$lowercase || !$number || !$specialChars || (strlen($password1) < 8 && strlen($password1) > 255)) { if(!$uppercase || !$lowercase || !$number || !$specialChars || (strlen($password1) >= 8 && strlen($password1) <= 255) ) {
return true; return true;
} }
} else return false;
else false;
} }

View File

@ -45,4 +45,4 @@ if(isset($_POST['login'])){
} }
} }

View File

@ -4,7 +4,7 @@ require_once "../Admin/Admin.php";
use Backend\Models\Group; use Backend\Models\Group;
session_start(); //session_start();
if(isAdmin()){ if(isAdmin()){
if(isset($_POST['restPassword'])){ if(isset($_POST['restPassword'])){
$group = Group::find($_POST['groupId']); $group = Group::find($_POST['groupId']);

View File

@ -16,7 +16,7 @@ $errors = array();
if(isset($_POST['regGroup'])){ if(isset($_POST['regGroup'])){
if(passwordValidate($pass = $_POST['password1'], $_POST['password2'])){ if(passwordValidate($pass = $_POST['password'])){
$group = new Group(); $group = new Group();
$group->gameJam()->associate(GameJam::find($_POST['gameJamId'])); $group->gameJam()->associate(GameJam::find($_POST['gameJamId']));

View File

@ -19,4 +19,8 @@ require "Group.php"; //Group has foreign keys to the GameJam, GameData and Passw
require "Password.php"; //Password has no foreign key require "Password.php"; //Password has no foreign key
require "KeyWord.php"; //Group has foreign keys to the Group require "KeyWord.php"; //Group has foreign keys to the Group
require "Vote.php"; require "Vote.php";
require "AdminUser.php"; require "AdminUser.php";
\Backend\Models\AdminUser::firstOrCreate([
'user_name' => 'admin', 'password' => password_hash("Aa123456&",PASSWORD_DEFAULT)
]);

View File

@ -1,8 +1,7 @@
<?php <?php
use Backend\Models\GameJam; use Backend\Models\GameJam;
require_once('../bootstrap.php');
require "../bootstrap.php";
$gameJam = GameJam::firstOrCreate([ $gameJam = GameJam::firstOrCreate([
@ -21,8 +20,7 @@ $gameJam = GameJam::firstOrCreate([
<input type="text" name="groupName" placeholder="Group name"> <input type="text" name="groupName" placeholder="Group name">
<input type="number" name="groupAmount" placeholder="Group Amount"> <input type="number" name="groupAmount" placeholder="Group Amount">
<input type="number" name="gameJamId" placeholder="Game Jam id"> <input type="number" name="gameJamId" placeholder="Game Jam id">
<input type="password" name="password1" placeholder="password"> <input type="password" name="password" placeholder="password">
<input type="password" name="password2" placeholder="password">
<input type="submit" name="regGroup" value="Register"> <input type="submit" name="regGroup" value="Register">
</form> </form>

View File

@ -5,11 +5,9 @@ use Illuminate\Database\Eloquent\Model as Eloquent;
class AdminUser extends Eloquent class AdminUser extends Eloquent
{ {
protected $fillable = [ protected $fillable = [
'user_name' 'user_name', 'password'
]; ];
protected $hidden =[
'password'
];
} }