diff --git a/tasks/guestBookDB/actions/comment.php b/tasks/guestBookDB/actions/comment.php
index d91f03f..acd167b 100644
--- a/tasks/guestBookDB/actions/comment.php
+++ b/tasks/guestBookDB/actions/comment.php
@@ -1,31 +1,25 @@
0) {
return;
}
-$string = file_get_contents("../data/data.json") ?? "[]";
-$json = json_decode($string);
+$db = DB::openConnection();
-array_push($json, ["time" => $time, "title" => $title, "name" => $name, "comment" => $comment]);
+$stmt = $db->prepare($insertCommentQuery);
+$stmt->bindValue(":UID", $user["id"]);
+$stmt->bindValue(":COM", $comment);
+$stmt->execute();
-file_put_contents("../data/data.json", json_encode($json));
+DB::closeConnection($db);
Headers::redirect("../");
diff --git a/tasks/guestBookDB/actions/login.php b/tasks/guestBookDB/actions/login.php
new file mode 100644
index 0000000..cdf3f48
--- /dev/null
+++ b/tasks/guestBookDB/actions/login.php
@@ -0,0 +1,74 @@
+ 0) {
+ Headers::redirect("../login");
+ return;
+}
+
+$db = DB::openConnection();
+
+$stmt = $db->prepare($loginQuery);
+$stmt->bindValue(":USR", $username);
+$stmt->execute();
+$user = $stmt->fetch();
+
+if ($user) {
+ if (password_verify($password, $user["passwort"])) {
+ $_SESSION["user"] = $user;
+ // REHASH for safety should it somehow change
+ if (password_needs_rehash($user["passwort"], PASSWORD_DEFAULT)) {
+ $newHash = password_hash($password, PASSWORD_DEFAULT);
+ $stmt = $db->prepare($updatePasswordQuery);
+ $stmt->bindValue(":PAS", $newHash);
+ $stmt->bindValue(":UID", $user["id"]);
+ $stmt->execute();
+ }
+ unset($_SESSION["user"]["passwort"]);
+ unset($_SESSION["user"]["confirmationcode"]);
+ } else {
+ array_push($_SESSION["error"], "Username or Password incorrect.");
+ }
+} else {
+ array_push($_SESSION["error"], "Username or Password incorrect.");
+}
+
+DB::closeConnection($db);
+
+if (count($_SESSION["error"]) > 0) {
+ Headers::redirect("../login");
+ return;
+}
+
+Headers::redirect("../");
diff --git a/tasks/guestBookDB/actions/logout.php b/tasks/guestBookDB/actions/logout.php
new file mode 100644
index 0000000..20b6810
--- /dev/null
+++ b/tasks/guestBookDB/actions/logout.php
@@ -0,0 +1,24 @@
+ 0) {
+ Headers::redirect("../register");
+ return;
+}
+
+$db = DB::openConnection();
+
+try {
+ $guid = guidv4();
+
+ $stmt = $db->prepare($insertUserQuery);
+ $stmt->bindValue(":USR", $username);
+ $stmt->bindValue(":PAS", password_hash($password, PASSWORD_DEFAULT));
+ $stmt->bindValue(":EMA", $email);
+ $stmt->bindValue(":COD", $guid);
+ $stmt->execute();
+
+ mail(
+ $email,
+ "Account activation GuestBookDB",
+ "Hello $username. To activate your account, visit https://userpage.fu-berlin.de/khofmann/phpCourse/tasks/guestBookDB/confirm?c=$guid"
+ );
+
+ array_push($_SESSION["message"], "Please confirm your account using the mail we sent you.");
+} catch (PDOException $e) {
+ if ($e->getCode() === "23000") {
+ array_push($_SESSION["error"], "A user with this username or email already exists");
+ } else {
+ array_push($_SESSION["error"], "SQL Error: {$e->getMessage()}");
+ }
+ Headers::redirect("../register");
+ return;
+}
+
+DB::closeConnection($db);
+
+Headers::redirect("../login");
diff --git a/tasks/guestBookDB/components/message.php b/tasks/guestBookDB/components/message.php
new file mode 100644
index 0000000..7b4a5fc
--- /dev/null
+++ b/tasks/guestBookDB/components/message.php
@@ -0,0 +1,7 @@
+
+
+ = $message ?>
+
+
\ No newline at end of file
diff --git a/tasks/guestBookDB/components/newComment.php b/tasks/guestBookDB/components/newComment.php
index 18d3869..13904b2 100644
--- a/tasks/guestBookDB/components/newComment.php
+++ b/tasks/guestBookDB/components/newComment.php
@@ -1,20 +1,7 @@
-