diff --git a/resources/templates/index.html b/resources/templates/index.html
index 1239132..bc08809 100644
--- a/resources/templates/index.html
+++ b/resources/templates/index.html
@@ -9,23 +9,7 @@
-
-
+
+ {% include "partials/index/form.html" %}
+
{% endblock %}
\ No newline at end of file
diff --git a/resources/templates/partials/index/form.html b/resources/templates/partials/index/form.html
new file mode 100644
index 0000000..31c2e32
--- /dev/null
+++ b/resources/templates/partials/index/form.html
@@ -0,0 +1,21 @@
+
\ No newline at end of file
diff --git a/resources/templates/partials/index/success.html b/resources/templates/partials/index/success.html
new file mode 100644
index 0000000..6ec4fa7
--- /dev/null
+++ b/resources/templates/partials/index/success.html
@@ -0,0 +1,17 @@
+
+
+
+ You are logged in as {{ name }}.
+
+
+
+
+
diff --git a/src/webui/mod.rs b/src/webui/mod.rs
index 86b60a9..141a752 100644
--- a/src/webui/mod.rs
+++ b/src/webui/mod.rs
@@ -103,6 +103,8 @@ pub async fn web_ui_main(connFact: SQLiteConnectionFactory,
actix_files::Files::new("/static", "./resources/static/").use_last_modified(true),
)
.service(views::index)
+ .service(views::login)
+ .service(views::logout)
.service(views::actions)
.service(views::overview)
.service(views::overview_submit_button)
diff --git a/src/webui/views.rs b/src/webui/views.rs
index b53affe..11e5937 100644
--- a/src/webui/views.rs
+++ b/src/webui/views.rs
@@ -26,7 +26,7 @@ pub async fn actions(tmpl_env: MiniJinjaRenderer) -> actix_web::Result) -> actix_web::Result {
let conn = connFactory.readonly().unwrap(); // todo; to proper 500
- let service_factory = ServiceFactory::new(& conn);
+ let service_factory = ServiceFactory::new(&conn);
let user_service = service_factory.get_user_service();
let users = user_service.list_users().unwrap();
let ctx = context! {
@@ -35,6 +35,29 @@ pub async fn overview(tmpl_env: MiniJinjaRenderer,
tmpl_env.render("overview.html", ctx)
}
+#[derive(Deserialize, Debug)]
+struct LoginPayload {
+ username: String,
+ password: String,
+}
+
+
+#[actix_web::post("/login")]
+pub async fn login(tmpl_env: MiniJinjaRenderer,
+ web::Json(form): web::Json) -> actix_web::Result {
+ let ctx = context! {
+ name => form.username,
+ };
+ tmpl_env.render("partials/index/success.html", ctx)
+}
+
+#[actix_web::post("/logout")]
+pub async fn logout(tmpl_env: MiniJinjaRenderer) -> actix_web::Result {
+ let ctx = context! {};
+ let res = tmpl_env.render("partials/index/form.html", ctx)?;
+ Ok(res.customize().insert_header(("Set-Cookie", "username=nobody")))
+}
+
#[actix_web::get("/partials/overview/submit_button")]
pub async fn overview_submit_button(
_req: HttpRequest,