diff --git a/Backend/Controllers/Admin/Admin.php b/Backend/Controllers/Admin/Admin.php index c394c4a..097b9a2 100644 --- a/Backend/Controllers/Admin/Admin.php +++ b/Backend/Controllers/Admin/Admin.php @@ -8,3 +8,12 @@ function isAdmin(): bool return isset($_SESSION['admin']); } +function makeAdminLogin(string $userName) +{ + setcookie("userName", $userName, [ + 'expires' => 0, + 'samesite' => 'Strict', + 'path' => '/' + ]); +} + diff --git a/Backend/Controllers/Admin/AdminLogin.php b/Backend/Controllers/Admin/AdminLogin.php index 813b3dd..08d6a4d 100644 --- a/Backend/Controllers/Admin/AdminLogin.php +++ b/Backend/Controllers/Admin/AdminLogin.php @@ -19,6 +19,7 @@ if(isset($_POST['aLogin'])){ $_SESSION['userName'] = $userName; $_SESSION['admin'] = true; $_SESSION['success'] = "You are now logged in"; + makeAdminLogin($userName); http_response_code(200); }else{ session_destroy(); diff --git a/Backend/Controllers/Group/Logout.php b/Backend/Controllers/Group/Logout.php index f8e4552..bf2e3fe 100644 --- a/Backend/Controllers/Group/Logout.php +++ b/Backend/Controllers/Group/Logout.php @@ -1,9 +1,10 @@ -1, 'samesite' => 'Strict', @@ -11,5 +12,6 @@ $cookieCon = array( ); setcookie("groupName", null, $cookieCon); setcookie("groupId", null, $cookieCon); +setcookie("userName", null, $cookieCon); echo http_response_code(200); \ No newline at end of file diff --git a/Backend/setup.php b/Backend/setup.php new file mode 100644 index 0000000..1ba6a68 --- /dev/null +++ b/Backend/setup.php @@ -0,0 +1,98 @@ +connect_error) { + die("Connection failed: " . $conn->connect_error); + } + $sql = "CREATE DATABASE ".$DBName; + if ($conn->query($sql) === TRUE) { + echo "Database created successfully"; + } else { + echo "Error creating database: " . $conn->error; + } + $conn->close(); + return array( + "driver" => "mysql", + "host" => $servername, + "database" => $DBName, + "username" => $username, + "password" => $password + ); +} + +/** + * @param string $DBName + * @return string[] + */ +function liteDB(string $DBName): array +{ + New SQLite3("Database/".$DBName.".sqlite"); + $test = array( + 'driver' => 'sqlite', + 'database' => realpath(dirname(__FILE__)."/Database/".$DBName.".sqlite") + //'Backend/Database/'.$DBName.'.sqlite' + ); + var_dump($test); + return $test; +} + + +$servername = "127.0.0.1"; +$username = "root"; +$password = "rootlog"; +$DBName = "gamejamdb"; +if(isset($_POST["dbSetup"])){ + + + switch($_POST["dbType"]){ + case "mysql": + $dbCon = myDB($_POST["dbServername"],$_POST["dbUsername"],$_POST["dbPassword"], $_POST["dbName"]); + break; + case "sqlite": + $dbCon = liteDB($_POST["dbName"]); + break; + default: + die("wrong dbType"); + } + + file_put_contents("../config/database.json", json_encode($dbCon)); + + require_once('../bootstrap.php'); + try{ + $capsule->Connection()->getPdo(); + } catch (\Exception $e) { + //file_put_contents("../config/database.json", NULL); + die("Could not connect to the database. Please check your configuration. error:" . $e ); + } + require_once ('Database/databaseMigration.php'); + AdminUser::firstOrCreate([ + 'user_name' => $_POST["AdminUsername"], 'password' => password_hash($_POST["AdminPassword"],PASSWORD_DEFAULT) + ]); + + + +}else{ + echo "not set"; + +} + + + + + + diff --git a/bootstrap.php b/bootstrap.php index 2da690d..1959089 100755 --- a/bootstrap.php +++ b/bootstrap.php @@ -1,13 +1,8 @@ addConnection([ - "driver" => "mysql", - "host" =>"localhost", - "database" => "TestDB", - "username" => "root", - "password" => "V#_xWL6_" -]); +$con = json_decode(file_get_contents('config/database.json', true), true); +$capsule->addConnection($con); $capsule->setAsGlobal(); $capsule->bootEloquent();