From f717080e8a08474cfd7173da52d9cd4cd2087f11 Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Fri, 20 Dec 2024 16:40:32 +0200 Subject: [PATCH 1/2] Small fixes and things --- Makefile | 3 +++ src/inc/database.php | 5 ++++- src/index.php | 4 ++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index b57960b..ec3db14 100644 --- a/Makefile +++ b/Makefile @@ -12,3 +12,6 @@ docker-run: data/ FORCE: cp -r src/data ./ chmod 777 data + +docker-run-dev: data/ src/ + docker run -v $(current_dir)src/:/var/www/html/ -v $(current_dir)data/:/var/www/html/data/ -p 8080:80 snuffler/snuffler-web:dev \ No newline at end of file diff --git a/src/inc/database.php b/src/inc/database.php index 2860e86..57f8fc0 100755 --- a/src/inc/database.php +++ b/src/inc/database.php @@ -102,7 +102,7 @@ class DataBase extends SQLite3 { function addPersona($userid, $handle, $name, $about=NULL, $colour=NULL) { $id = hexdec(uniqid()); - $sql = "INSERT INTO personas (id, userid, handle, name, colour) VALUES ('$id', '$userid', '$handle', '$about', '$colour');"; + $sql = "INSERT INTO personas (id, userid, handle, name, about, colour) VALUES ('$id', '$userid', '$handle', '$name', '$about', '$colour');"; $ret = $this->exec($sql); if(!$ret) { die($this->lastErrorMsg()); @@ -125,6 +125,9 @@ class DataBase extends SQLite3 { return false; } $dbhash = $ret[0]; + if(!$dbhash) { + return false; + } return password_verify($password, $dbhash); } diff --git a/src/index.php b/src/index.php index 801fb0c..801e3b0 100755 --- a/src/index.php +++ b/src/index.php @@ -80,8 +80,8 @@ $posts = array_reverse($database->getPosts()); foreach($posts as $post) { echo '
'; echo ''; echo '

' . $post["post.text"] . '

'; From de4cbe9ee63762e19dfaace81c91cf4517849c81 Mon Sep 17 00:00:00 2001 From: Jarkko Toivanen Date: Fri, 20 Dec 2024 16:41:21 +0200 Subject: [PATCH 2/2] Ability to post This is HUUUUUUUGE milestone B) --- src/inc/database.php | 14 ++++++++++++++ src/index.php | 12 ++++++++---- src/post.php | 14 ++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 src/post.php diff --git a/src/inc/database.php b/src/inc/database.php index 57f8fc0..da03ecb 100755 --- a/src/inc/database.php +++ b/src/inc/database.php @@ -195,5 +195,19 @@ class DataBase extends SQLite3 { } return $array; } + + function getPersonas($userid=NULL) { + if(!$userid) { + $userid = $this->getAuthedUserId(); + } + $sql = "SELECT * FROM personas AS persona WHERE userid='$userid' ORDER BY name;"; + + $ret = $this->query($sql); + $array = array(); + while ($row = $ret->fetchArray(SQLITE3_ASSOC)) { + array_push($array, $row); + } + return $array; + } } ?> diff --git a/src/index.php b/src/index.php index 801e3b0..572542d 100755 --- a/src/index.php +++ b/src/index.php @@ -55,12 +55,16 @@ if(!$database) { } else { ?> LOG OUT -
+
- + getPersonas(); + foreach($personas as $persona) { + echo ""; + } + ?>
diff --git a/src/post.php b/src/post.php new file mode 100644 index 0000000..e69d9c0 --- /dev/null +++ b/src/post.php @@ -0,0 +1,14 @@ +getAuthedUserId(); +$persid = $_POST['persona']; // TODO: CHECK OWNERSHIP! (db schema?) +if($userid) { + $db->addPost($_POST['text'], $userid, $persid); +} +header("Location: /"); +?>