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
*/
function isAdmin(){
function isAdmin(): bool
{
session_start();
return isset($_SESSION['admin']);
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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