Merge remote-tracking branch 'origin/main' into main
This commit is contained in:
commit
0ea676a033
|
@ -8,3 +8,15 @@ function isAdmin(): bool
|
||||||
return isset($_SESSION['admin']);
|
return isset($_SESSION['admin']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $userName
|
||||||
|
*/
|
||||||
|
function makeAdminLogin(string $userName)
|
||||||
|
{
|
||||||
|
setcookie("userName", $userName, [
|
||||||
|
'expires' => 0,
|
||||||
|
'samesite' => 'Strict',
|
||||||
|
'path' => '/'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,6 +20,7 @@ if(isset($_POST['aLogin'])){
|
||||||
$_SESSION['admin'] = true;
|
$_SESSION['admin'] = true;
|
||||||
$_SESSION['success'] = "You are now logged in";
|
$_SESSION['success'] = "You are now logged in";
|
||||||
http_response_code(200);
|
http_response_code(200);
|
||||||
|
makeAdminLogin($userName);
|
||||||
}else{
|
}else{
|
||||||
session_destroy();
|
session_destroy();
|
||||||
http_response_code(401);
|
http_response_code(401);
|
||||||
|
|
|
@ -5,7 +5,8 @@
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
|
@ -25,7 +26,6 @@ function ZipFileHandler(string $gameFileName, string $gameFileTmp){
|
||||||
echo json_encode(["message" => "Wrong file type gameFile"]);
|
echo json_encode(["message" => "Wrong file type gameFile"]);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,8 @@ return NULL;
|
||||||
* @param string $thumbnailFileTmp
|
* @param string $thumbnailFileTmp
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
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));
|
||||||
|
|
||||||
|
@ -53,5 +54,4 @@ function imagesFileHandler(string $thumbnailFileName, string $thumbnailFileTmp){
|
||||||
echo json_encode(["message" => "Wrong file type thumbnailFile"]);
|
echo json_encode(["message" => "Wrong file type thumbnailFile"]);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
return NULL;
|
|
||||||
}
|
}
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
session_start();
|
session_start();
|
||||||
|
session_unset();
|
||||||
session_destroy();
|
session_destroy();
|
||||||
|
|
||||||
$cookieCon = array(
|
$cookieCon = array(
|
||||||
|
@ -11,5 +11,6 @@ $cookieCon = array(
|
||||||
);
|
);
|
||||||
setcookie("groupName", null, $cookieCon);
|
setcookie("groupName", null, $cookieCon);
|
||||||
setcookie("groupId", null, $cookieCon);
|
setcookie("groupId", null, $cookieCon);
|
||||||
|
setcookie("userName", null, $cookieCon);
|
||||||
|
|
||||||
echo http_response_code(200);
|
echo http_response_code(200);
|
|
@ -17,13 +17,15 @@ function myDB(string $servername, string $username, string $password, string $DB
|
||||||
$conn = new mysqli($servername, $username, $password);
|
$conn = new mysqli($servername, $username, $password);
|
||||||
|
|
||||||
if ($conn->connect_error) {
|
if ($conn->connect_error) {
|
||||||
die("Connection failed: " . $conn->connect_error);
|
http_response_code(400);
|
||||||
|
echo json_encode(["message" => $conn->connect_error]);
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
$sql = "CREATE DATABASE ".$DBName;
|
$sql = "CREATE DATABASE ".$DBName;
|
||||||
if ($conn->query($sql) === TRUE) {
|
if ($conn->query($sql) === FALSE) {
|
||||||
echo "Database created successfully";
|
http_response_code(400);
|
||||||
} else {
|
echo json_encode(["message" => $conn->error]);
|
||||||
echo "Error creating database: " . $conn->error;
|
exit();
|
||||||
}
|
}
|
||||||
$conn->close();
|
$conn->close();
|
||||||
return array(
|
return array(
|
||||||
|
@ -41,24 +43,33 @@ function myDB(string $servername, string $username, string $password, string $DB
|
||||||
*/
|
*/
|
||||||
function liteDB(string $DBName): array
|
function liteDB(string $DBName): array
|
||||||
{
|
{
|
||||||
New SQLite3("Database/".$DBName.".sqlite");
|
$DBName = $DBName.".sqlite";
|
||||||
$test = array(
|
if(file_exists($DBName)){
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(["message" => "database already exits"]);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
New SQLite3($DBName);
|
||||||
|
return array(
|
||||||
'driver' => 'sqlite',
|
'driver' => 'sqlite',
|
||||||
'database' => realpath(dirname(__FILE__)."/Database/".$DBName.".sqlite")
|
'database' => realpath(dirname(__FILE__)."/".$DBName)
|
||||||
//'Backend/Database/'.$DBName.'.sqlite'
|
|
||||||
);
|
);
|
||||||
var_dump($test);
|
}
|
||||||
return $test;
|
|
||||||
|
$conFilePath = '../config/database.json';
|
||||||
|
if(!file_exists($conFilePath)){
|
||||||
|
$confile = fopen($conFilePath, "w");
|
||||||
|
fclose($confile);
|
||||||
|
}
|
||||||
|
if (0 !== filesize($conFilePath)){
|
||||||
|
http_response_code(400);
|
||||||
|
echo json_encode(["message" => "already have database connection"]);
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$servername = "localhost";
|
|
||||||
$username = "root";
|
|
||||||
$password = "V#_xWL6_";
|
|
||||||
$DBName = "TestDB";
|
|
||||||
if(isset($_POST["dbSetup"])){
|
if(isset($_POST["dbSetup"])){
|
||||||
|
|
||||||
|
|
||||||
switch($_POST["dbType"]){
|
switch($_POST["dbType"]){
|
||||||
case "mysql":
|
case "mysql":
|
||||||
$dbCon = myDB($_POST["dbServername"],$_POST["dbUsername"],$_POST["dbPassword"], $_POST["dbName"]);
|
$dbCon = myDB($_POST["dbServername"],$_POST["dbUsername"],$_POST["dbPassword"], $_POST["dbName"]);
|
||||||
|
@ -67,28 +78,30 @@ if(isset($_POST["dbSetup"])){
|
||||||
$dbCon = liteDB($_POST["dbName"]);
|
$dbCon = liteDB($_POST["dbName"]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
die("wrong dbType");
|
http_response_code(400);
|
||||||
|
echo json_encode(["message" => "database type is wrong"]);
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
file_put_contents("../config/database.json", json_encode($dbCon));
|
file_put_contents($conFilePath, json_encode($dbCon));
|
||||||
|
|
||||||
require_once('../bootstrap.php');
|
require_once('../bootstrap.php');
|
||||||
try{
|
try{
|
||||||
$capsule->Connection()->getPdo();
|
$capsule->Connection()->getPdo();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
//file_put_contents("../config/database.json", NULL);
|
http_response_code(400);
|
||||||
die("Could not connect to the database. Please check your configuration. error:" . $e );
|
file_put_contents($conFilePath, NULL);
|
||||||
|
echo json_encode(["message" => "Could not connect to the database. Please check your configuration. error:"]);
|
||||||
|
exit();
|
||||||
}
|
}
|
||||||
require_once ('Database/databaseMigration.php');
|
require_once ('Database/databaseMigration.php');
|
||||||
AdminUser::firstOrCreate([
|
AdminUser::firstOrCreate([
|
||||||
'user_name' => $_POST["AdminUsername"], 'password' => password_hash($_POST["AdminPassword"],PASSWORD_DEFAULT)
|
'user_name' => $_POST["AdminUsername"], 'password' => password_hash($_POST["AdminPassword"],PASSWORD_DEFAULT)
|
||||||
]);
|
]);
|
||||||
|
http_response_code(201);
|
||||||
|
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
echo "not set";
|
http_response_code(400);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue