aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-10-31 00:39:43 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-10-31 00:39:43 +0200
commit320c5d4ba6cbe784d0c0f211c898cf051a5228b3 (patch)
tree1301a57221f72c7f0363c343e3b1f1a5f0071ded
parent60f5f5538c4bfd9582c0bba648b317ff3ce4b1f8 (diff)
Format createDate and publishDate with std::strftime().
* Disallow access to any blog entry individually. Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--src/content/blog/Blog.cpp57
-rw-r--r--src/content/blog/Blog.hpp3
-rw-r--r--wwwroot/blog/index.html2
-rw-r--r--wwwroot/blog/my-second-blog-entry.json3
-rw-r--r--wwwroot/blog/my-third-blog-entry.json3
-rw-r--r--wwwroot/blog/my-very-first-blog-entry.json3
6 files changed, 56 insertions, 15 deletions
diff --git a/src/content/blog/Blog.cpp b/src/content/blog/Blog.cpp
index 03ccb28..52951de 100644
--- a/src/content/blog/Blog.cpp
+++ b/src/content/blog/Blog.cpp
@@ -80,7 +80,10 @@ bool Blog::Render(RequestResponse & rr, RenderData & rd, std::string & out)
}
else
{
- GetBlogPost(rd["blog_post"], rr.GetUriPath());
+ if (GetBlogPost(rd["blog_post"], rr.GetUriPath()) == false)
+ {
+ return false;
+ }
}
return true;
@@ -168,6 +171,12 @@ bool Blog::ValidateAndSetMetdadata(BlogMetadata const & blogMetadata, BlogEntry
}
blogEntry->published = blogMetadata["published"];
+ if (validateMetadata(blogMetadata, "accessAllowed") == false)
+ {
+ retval = false;
+ }
+ blogEntry->accessAllowed = blogMetadata["accessAllowed"];
+
return retval;
}
@@ -201,14 +210,35 @@ bool Blog::ValidateEntries()
void Blog::FillRenderData(RenderData & re, BlogEntry const & be)
{
- re["filename"] = be->filename;
- re["title"] = be->title;
- re["tags"] = be->tags;
- re["author"] = be->author;
- re["createDate"] = be->createDate;
- re["publishDate"] = be->publishDate;
- re["published"] = be->published;
- re["content"] = "";
+ re["filename"] = be->filename;
+ re["title"] = be->title;
+ re["tags"] = be->tags;
+ re["author"] = be->author;
+ {
+ char tmstr[64];
+ if (std::strftime(tmstr, sizeof(tmstr), "%c", std::localtime(&be->createDate)) > 0)
+ {
+ re["createDate"] = tmstr;
+ }
+ else
+ {
+ re["createDate"] = "<strftime error>";
+ }
+ }
+ {
+ char tmstr[64];
+ if (std::strftime(tmstr, sizeof(tmstr), "%c", std::localtime(&be->publishDate)) > 0)
+ {
+ re["publishDate"] = tmstr;
+ }
+ else
+ {
+ re["publishDate"] = "<strftime error>";
+ }
+ }
+ re["published"] = be->published;
+ re["accessAllowed"] = be->accessAllowed;
+ re["content"] = "";
}
void Blog::GenerateBlogListing(RenderData & rd)
@@ -230,14 +260,21 @@ void Blog::GenerateBlogListing(RenderData & rd)
}
}
-void Blog::GetBlogPost(RenderData & rd, char const * blogPostUri)
+bool Blog::GetBlogPost(RenderData & rd, char const * blogPostUri)
{
RenderData re;
if (m_BlogContents.HasMarkdownFile(blogPostUri) == true)
{
+ if (m_BlogEntries[blogPostUri]->accessAllowed == false)
+ {
+ return false;
+ }
+
FillRenderData(re, m_BlogEntries[blogPostUri]);
re["content"] = m_BlogContents.GetMarkdownHTML(blogPostUri)->c_str();
}
rd = re;
+
+ return true;
}
diff --git a/src/content/blog/Blog.hpp b/src/content/blog/Blog.hpp
index abdb522..637ea7b 100644
--- a/src/content/blog/Blog.hpp
+++ b/src/content/blog/Blog.hpp
@@ -21,6 +21,7 @@ struct blog_entry
std::time_t createDate;
std::time_t publishDate;
bool published;
+ bool accessAllowed;
};
using BlogMetadata = inja::json;
@@ -45,7 +46,7 @@ public:
bool ValidateEntries();
void FillRenderData(RenderData & re, BlogEntry const & be);
void GenerateBlogListing(RenderData & rd);
- void GetBlogPost(RenderData & rd, char const * blogPostUri);
+ bool GetBlogPost(RenderData & rd, char const * blogPostUri);
private:
std::string m_UriBasePath;
diff --git a/wwwroot/blog/index.html b/wwwroot/blog/index.html
index 9198152..a4c520a 100644
--- a/wwwroot/blog/index.html
+++ b/wwwroot/blog/index.html
@@ -3,7 +3,7 @@
<b>blabla</b>
Test fn....: <b>{{ test_fn }}</b><br>
Test RetFN.: <b>{{ test_return_true }}</b><br><br><br>
-{% if exists("blog_listing") and length(blog_listing) > 0 %}
+{% if exists("blog_listing") %}
<table>
## for entry in blog_listing
<tr>
diff --git a/wwwroot/blog/my-second-blog-entry.json b/wwwroot/blog/my-second-blog-entry.json
index ecb2b8b..c1a4fe6 100644
--- a/wwwroot/blog/my-second-blog-entry.json
+++ b/wwwroot/blog/my-second-blog-entry.json
@@ -4,5 +4,6 @@
"author": "lns",
"createDate": "23.02.1989 23:59",
"publishDate": "30.12.2020 1:00",
- "published": true
+ "published": true,
+ "accessAllowed": false
}
diff --git a/wwwroot/blog/my-third-blog-entry.json b/wwwroot/blog/my-third-blog-entry.json
index 9682cd2..3478508 100644
--- a/wwwroot/blog/my-third-blog-entry.json
+++ b/wwwroot/blog/my-third-blog-entry.json
@@ -4,5 +4,6 @@
"author": "lns",
"createDate": "24.02.1989 23:59",
"publishDate": "31.12.2020 1:00",
- "published": false
+ "published": false,
+ "accessAllowed": false
}
diff --git a/wwwroot/blog/my-very-first-blog-entry.json b/wwwroot/blog/my-very-first-blog-entry.json
index 52f52f7..e10fb2c 100644
--- a/wwwroot/blog/my-very-first-blog-entry.json
+++ b/wwwroot/blog/my-very-first-blog-entry.json
@@ -4,5 +4,6 @@
"author": "lns",
"createDate": "22.02.1989 23:59",
"publishDate": "31.12.2020 1:00",
- "published": true
+ "published": true,
+ "accessAllowed": true
}