diff --git a/api/login/getcookies.php b/api/login/getcookies.php new file mode 100644 index 0000000..ca73ebc --- /dev/null +++ b/api/login/getcookies.php @@ -0,0 +1,46 @@ +getDB(); + +if ($_SERVER["REQUEST_METHOD"] == "POST") { + if (!isset($_POST["username"]) || !isset($_POST["passwd"])) { + die("Username or Password are missing"); + } + + $user = $_POST["username"]; + $passwd = hash("sha256", $_POST["passwd"]); + + $sql = "SELECT username, passwd FROM users WHERE username = :username AND passwd = :passwd"; + $stmt = $db->prepare($sql); + $stmt->execute([ + ':username' => $user, + ':passwd' => $passwd + ]); + + $result = $stmt->fetch(PDO::FETCH_ASSOC); + + if ($result) { + $config = $mcServ->getConf(); + + $session["session_id"] = $mcServ->generateSessionID(); + $device_id = rand(1, 999); + + $json[$device_id] = json_encode($session); + + file_put_contents($config["PATH"] . "/tmp/user_sessions/" . $admin_user . ".json", json_encode($json)); + + setcookie("session_id", $session["session_id"], time() + 3600, "/"); + setcookie("device_id", $device_id, time() + 3600, "/"); + setcookie("username", $user, time() + 3600, "/"); + + header("Location: /admin"); + exit; + + }else{ + header("Location: /login.php?passwdIsFalse=true"); + exit; + } +} +?> \ No newline at end of file diff --git a/api/setup/setup.php b/api/setup/setup.php index a9cba35..eb9a86f 100755 --- a/api/setup/setup.php +++ b/api/setup/setup.php @@ -1,10 +1,6 @@ checkConf()) { } if (!$mcServ->checkLogin()) { - /*header("Location: /login.php"); - exit;*/ + header("Location: /login.php"); + exit; }else{ echo "angemeldet"; } diff --git a/front/login.php b/front/login.php index f444e0b..2a241a3 100755 --- a/front/login.php +++ b/front/login.php @@ -1,7 +1,13 @@ @@ -20,10 +26,16 @@ if ($_SERVER["REQUEST_METHOD"] == "POST") {