From 4583b3f1f6516fa037ff0a2ef4e3df72ba42c174 Mon Sep 17 00:00:00 2001 From: Wisdurm Date: Fri, 28 Nov 2025 13:16:14 +0200 Subject: [PATCH] css --- info.txt | 1 + src/main.cpp | 14 ++++++++++++-- templates/admin.html | 40 +++++++++++++++++++++++++--------------- templates/index.html | 14 ++++++++------ templates/login.html | 30 +++++++++++++++++++----------- 5 files changed, 65 insertions(+), 34 deletions(-) diff --git a/info.txt b/info.txt index 4f2d4c3..a9ad6c9 100644 --- a/info.txt +++ b/info.txt @@ -1,2 +1,3 @@ Olemme Jaakon alaisia + diff --git a/src/main.cpp b/src/main.cpp index 5139375..abad833 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,7 +84,9 @@ int main() std::string info; CROW_ROUTE(app, "/") - .methods("GET"_method, "POST"_method)([&asunnot, &info](){ + .methods("GET"_method, "POST"_method)([&app, &asunnot, &info](const crow::request& req){ + auto& session = app.get_context(req); + auto page = crow::mustache::load("index.html"); crow::json::wvalue asunnotJson; for (int i = 0; i < asunnot.size(); ++i) { @@ -92,6 +94,14 @@ int main() asunnotJson[i]["kuva"] = asunnot.at(i).kuvaPolku; } crow::mustache::context ctx({{"asunnot", asunnotJson}, {"tieto", info}}); + // Login homma + if (session.get("name","_NO_") == "_NO_") { + ctx["link-text"] = "Kirjaudu"; + ctx["link-link"] = "login"; + } else { + ctx["link-text"] = "Admin"; + ctx["link-link"] = "admin"; + } return page.render(ctx); }); @@ -115,7 +125,7 @@ int main() // Aseta session muuttujat session.set("name", reqName); // Kun POST request ohi, redirect admin sivulle - res.redirect("/admin"); + res.redirect("/"); res.end(); return; } diff --git a/templates/admin.html b/templates/admin.html index a593169..ef37175 100644 --- a/templates/admin.html +++ b/templates/admin.html @@ -3,25 +3,35 @@ + + Admin -
- Tietoa meistä: -
- - -
+
+
+ Tietoa meistä +
+
+
+

+ +
+
-
- Lisää asuntola -
-
-
-
-
- -
+
+
+ Lisää asuntola +
+
+
+
+
+
+
+ +
+
diff --git a/templates/index.html b/templates/index.html index e1684b4..cfe49f2 100644 --- a/templates/index.html +++ b/templates/index.html @@ -17,15 +17,17 @@
@@ -33,7 +35,7 @@
-

Asunnot

+

Asunnot

{{#asunnot}}
@@ -43,7 +45,7 @@
{{/asunnot}}
-

Tietoa meistä

+

Tietoa meistä

{{ tieto }}

Meidän tiimi

diff --git a/templates/login.html b/templates/login.html index b8f081a..5ffb19a 100644 --- a/templates/login.html +++ b/templates/login.html @@ -3,19 +3,27 @@ - + + + Login - {{#name}} -

Kirjauduttu sisään, tervetuloa {{name}}!

- {{/name}} -
-
-
-
-
- -
+
+ {{#name}} +
+

Kirjauduttu sisään, tervetuloa {{name}}!

+
+ {{/name}} +
+
+
+
+
+

+ +
+
+
-- 2.47.3