profile pages
This commit is contained in:
@@ -34,6 +34,3 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div id="posts">
|
<div id="posts">
|
||||||
<div id="posts-header">
|
|
||||||
<h1>posts</h1>
|
|
||||||
</div>
|
|
||||||
|
|||||||
@@ -61,6 +61,11 @@ img {
|
|||||||
display: flex;
|
display: flex;
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: lime;
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
nav {
|
nav {
|
||||||
background: rgb(25, 25, 25);
|
background: rgb(25, 25, 25);
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ int main() {
|
|||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << headerTop << "<meta content='Chookchat' property='og:title' /><meta content='See posts from cool people' property='og:description' />" << headerBottom;
|
ss << headerTop << "<meta content='Chookchat' property='og:title' /><meta content='See posts from cool people' property='og:description' />" << headerBottom;
|
||||||
|
ss << "<div id='posts-header'><h1>posts</h1></div>";
|
||||||
|
|
||||||
std::lock_guard<std::mutex> lock(data_mutex);
|
std::lock_guard<std::mutex> lock(data_mutex);
|
||||||
|
|
||||||
@@ -214,6 +215,36 @@ int main() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
svr.Get("/profile/:username", [&headerTop, &headerBottom, &footer, &e404, &database, &data_mutex](const httplib::Request& request, httplib::Response& response){
|
||||||
|
std::string username = request.path_params.at("username");
|
||||||
|
std::lock_guard<std::mutex> lock(data_mutex);
|
||||||
|
try {
|
||||||
|
std::optional<User> user = database.getUserByName(username);
|
||||||
|
if (!user.has_value()) {
|
||||||
|
response.status = 404;
|
||||||
|
response.set_content(e404, "text/html");
|
||||||
|
}
|
||||||
|
std::vector<Post> posts = database.getUserPosts(user->id);
|
||||||
|
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << headerTop << "<meta content='See posts from " << username << " on Chookchat' property='og:title' />" << headerBottom;
|
||||||
|
ss << "<div id='posts-header'><h1>" << username << "'s posts</h1></div>";
|
||||||
|
for (const auto& post : posts) {
|
||||||
|
ss << post.genHtml();
|
||||||
|
}
|
||||||
|
ss << footer;
|
||||||
|
|
||||||
|
response.set_content(ss.str(), "text/html");
|
||||||
|
} catch (const std::runtime_error& e) {
|
||||||
|
response.status = 500;
|
||||||
|
response.set_content("<p>there was an error :( it is: " + std::string(e.what()) + "</p>", "text/html");
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
response.status = 500;
|
||||||
|
response.set_content("<p>there was an error :( it is: " + std::string(e.what()) + "</p>", "text/html");
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
// endpoint to be used by HTML forms
|
// endpoint to be used by HTML forms
|
||||||
svr.Post("/make_post", [&database, &data_mutex](const httplib::Request& request, httplib::Response& response) {
|
svr.Post("/make_post", [&database, &data_mutex](const httplib::Request& request, httplib::Response& response) {
|
||||||
|
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ std::string Post::genHtml() const {
|
|||||||
ts = *localtime(&time);
|
ts = *localtime(&time);
|
||||||
strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
|
strftime(buf, sizeof(buf), "%a %Y-%m-%d %H:%M:%S %Z", &ts);
|
||||||
|
|
||||||
ss << "<p class='postinfo'><i>" << user << "</i> posted this at " << buf << "</p>\n";
|
ss << "<p class='postinfo'><i><a href='/profile/" << user << "'>" << user << "</a></i> posted this at " << buf << "</p>\n";
|
||||||
|
|
||||||
ss << content;
|
ss << content;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user