-
-
- text($p["content"]);
- echo $strContent;
- ?>
+
+
+ text($p["content"]); ?>
-
">edit
+
+
+
by = $p["display_name"] ?? $p["user_name"] ?? $p["email"]; ?>
+
on = $p["created"]; ?> UTC
+
+
+
+
+
+
+
+
+
+
Sorry, there is nothing here to show.
+
+
+
+
+
+
+
+
diff --git a/pages/post/index.php b/pages/post/index.php
new file mode 100644
index 0000000..fe1a6d9
--- /dev/null
+++ b/pages/post/index.php
@@ -0,0 +1,123 @@
+ 0)
+ {
+ $varRows = $c->query("SELECT * from posts where id = ?", $strId);
+
+ if (count($varRows) !== 1)
+ {
+ BootstrapRender::message("Zero or more than one row returned", "danger");
+ Respond::redirect("/post");
+ }
+
+ $varRow = $varRows[0];
+ $strPath = $varRow["path"];
+ $strContent = $varRow["content"];
+ }
+
+
+ if (Request::posts("path", "content"))
+ {
+ $strPath = Request::getPosted("path");
+ $strContent = Request::getPosted("content");
+
+ if ($strId == null || strlen($strId) < 1)
+ {
+ $c->query(
+ "INSERT into posts (email, path, content)
+ values (?, ?, ?)",
+ $varUser["email"],
+ $strPath,
+ $strContent);
+
+ $strId = $c->query("SELECT * from posts where rowid = last_insert_rowid()")[0]["id"];
+ }
+
+ if (strlen($strContent) < 1)
+ {
+ $c->query("DELETE from posts where id = ?", $strId);
+ BootstrapRender::message("Post deleted successfully.", "success");
+ Respond::redirect("/post");
+ }
+
+ $c->query(
+ "UPDATE posts
+ set
+ path = ?,
+ content = ?,
+ updated = current_timestamp
+ where
+ id = ?",
+ $strPath,
+ $strContent,
+ $strId);
+
+ Respond::redirect("/post/{$strId}");
+ }
+?>
+
+
+
+
+
+
diff --git a/pages/user/info.php b/pages/user/info.php
index 8a1c24c..b16b30f 100644
--- a/pages/user/info.php
+++ b/pages/user/info.php
@@ -5,13 +5,6 @@
if (UserAuth::getUser() == null)
Respond::redirect("/user/signin");
- $c->query(
- "CREATE table if not exists user_info (
- id integer primary key autoincrement,
- email text not null unique,
- user_name text null,
- display_name text null)");
-
$varUser = UserAuth::getUser();
$strUsername = $varUser["user_name"] ?? "";
$strDisplayName = $varUser["display_name"] ?? "";
@@ -30,7 +23,7 @@
throw new Exception("Username must be alphanumeric characters only");
$c->query(
- "INSERT or replace into user_info (email, user_name, display_name)
+ "INSERT or replace into users (email, user_name, display_name)
select
?,
?,
diff --git a/pages/user/list.php b/pages/user/list.php
index e5b1c8f..2581802 100644
--- a/pages/user/list.php
+++ b/pages/user/list.php
@@ -1,5 +1,5 @@
diff --git a/pages/user/permissions.php b/pages/user/permissions.php
index 544ac51..350f393 100644
--- a/pages/user/permissions.php
+++ b/pages/user/permissions.php
@@ -1,5 +1,5 @@
diff --git a/pages/user/register.php b/pages/user/register.php
index 2614f27..350da54 100644
--- a/pages/user/register.php
+++ b/pages/user/register.php
@@ -3,7 +3,7 @@
try
{
- $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"];
+ $intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"];
if ($intUserCount < 1)
{
@@ -27,13 +27,7 @@
if (strlen($strPassword) < 6)
throw new Exception("Password must be at least 6 characters");
- $c->query(
- "CREATE table if not exists user (
- id integer primary key autoincrement,
- email text not null unique,
- hash text not null)");
-
- $varUsers = $c->query("SELECT * from user where email like ?", $strEmail);
+ $varUsers = $c->query("SELECT * from credentials where email like ?", $strEmail);
if (count($varUsers) > 0)
throw new Exception("E-mail address in use");
@@ -41,21 +35,18 @@
$strHash = sha1($strPassword);
$c->query(
- "INSERT into user (email, hash) values (?, ?)",
+ "INSERT into credentials (email, hash) values (?, ?)",
$strEmail,
$strHash);
- $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"];
+ $intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"];
if ($intUserCount == 1)
{
- // Calling this ensures permission table:
- UserAuth::hasPermission("dummy");
-
$c->query(
- "INSERT into permission (email, name)
- values (?, 'admin')",
- $strEmail);
+ "INSERT into permissions (email, permission) values (?, ?)",
+ $strEmail,
+ "admin");
}
BootstrapRender::message("Registration was a success, please sign in to continue.");
diff --git a/pages/user/signin.php b/pages/user/signin.php
index f606412..9965e5f 100644
--- a/pages/user/signin.php
+++ b/pages/user/signin.php
@@ -3,7 +3,7 @@
try
{
- $intUserCount = $c->query("SELECT count(*) as val from user")[0]["val"];
+ $intUserCount = $c->query("SELECT count(*) as c from credentials")[0]["c"];
if ($intUserCount < 1)
Respond::redirect("/user/register");
@@ -15,7 +15,7 @@
$strHash = sha1($strPassword);
$varUsers = $c->query(
"SELECT *
- from user
+ from credentials
where
email like ?
and hash = ?",
@@ -27,14 +27,8 @@
$strToken = sha1(microtime());
- $c->query("CREATE table if not exists tokens (
- id integer primary key autoincrement,
- email text not null,
- token text not null,
- expires timestamp null)");
-
$c->query(
- "INSERT into tokens (email, token) values (?, ?)",
+ "INSERT into sessions (email, token) values (?, ?)",
$strEmail,
$strToken);
diff --git a/pages/user/signout.php b/pages/user/signout.php
index 01c1310..cea6003 100644
--- a/pages/user/signout.php
+++ b/pages/user/signout.php
@@ -7,7 +7,7 @@
if (Request::getArg(0) == "all")
{
$c->query(
- "UPDATE tokens
+ "UPDATE sessions
set
expires = current_timestamp
where email = ?",
@@ -16,7 +16,7 @@
else
{
$c->query(
- "UPDATE tokens
+ "UPDATE sessions
set
expires = current_timestamp
where token = ?",