From 6abb380c056829a8b31fe9939f2ada729cba1bf8 Mon Sep 17 00:00:00 2001 From: Fabrice Bellamy <12b@distrilab.fr> Date: Mon, 21 Oct 2024 22:20:39 +0200 Subject: [PATCH] Add views to test user login --- nixin_farm_ssr/assets/views/base.html | 4 +- nixin_farm_ssr/assets/views/home/hello.html | 12 ---- nixin_farm_ssr/assets/views/home/index.html | 15 ++++ nixin_farm_ssr/assets/views/home/login.html | 68 +++++++++++++++++++ .../assets/views/home/register.html | 0 .../assets/views/home/resetpwd.html | 0 nixin_farm_ssr/src/controllers/home.rs | 34 +++++++++- nixin_farm_ssr/src/views/home.rs | 22 ++++++ nixin_farm_ssr/src/views/mod.rs | 2 + 9 files changed, 142 insertions(+), 15 deletions(-) delete mode 100644 nixin_farm_ssr/assets/views/home/hello.html create mode 100644 nixin_farm_ssr/assets/views/home/index.html create mode 100644 nixin_farm_ssr/assets/views/home/login.html create mode 100644 nixin_farm_ssr/assets/views/home/register.html create mode 100644 nixin_farm_ssr/assets/views/home/resetpwd.html create mode 100644 nixin_farm_ssr/src/views/home.rs diff --git a/nixin_farm_ssr/assets/views/base.html b/nixin_farm_ssr/assets/views/base.html index d0d8c43..0857326 100644 --- a/nixin_farm_ssr/assets/views/base.html +++ b/nixin_farm_ssr/assets/views/base.html @@ -1,6 +1,6 @@ - + {% block title %}{% endblock title %} @@ -12,7 +12,7 @@ {% endblock head %} - +
{% block content %} {% endblock content %} diff --git a/nixin_farm_ssr/assets/views/home/hello.html b/nixin_farm_ssr/assets/views/home/hello.html deleted file mode 100644 index 6b97c39..0000000 --- a/nixin_farm_ssr/assets/views/home/hello.html +++ /dev/null @@ -1,12 +0,0 @@ - - -
- find this tera template at assets/views/home/hello.html: -
-
- {{ t(key="hello-world", lang="en-US") }}, -
- {{ t(key="hello-world", lang="de-DE") }} - - - \ No newline at end of file diff --git a/nixin_farm_ssr/assets/views/home/index.html b/nixin_farm_ssr/assets/views/home/index.html new file mode 100644 index 0000000..decca6a --- /dev/null +++ b/nixin_farm_ssr/assets/views/home/index.html @@ -0,0 +1,15 @@ +{% extends "base.html" %} + +{% block title %} +Login +{% endblock title %} + +{% block content %} +
+
+ NixiN +

Index

+
+ +
+{% endblock content %} \ No newline at end of file diff --git a/nixin_farm_ssr/assets/views/home/login.html b/nixin_farm_ssr/assets/views/home/login.html new file mode 100644 index 0000000..01e75f2 --- /dev/null +++ b/nixin_farm_ssr/assets/views/home/login.html @@ -0,0 +1,68 @@ +{% extends "base.html" %} + +{% block title %} +Login +{% endblock title %} + +{% block content %} + + +
+
+ NixiN +

Sign in to your account

+
+ +
+
+
+ +
+ +
+
+ +
+
+ + +
+
+ +
+
+ +
+ +
+
+ +

+ No account yet? + Register a new account +

+
+
+{% endblock content %} \ No newline at end of file diff --git a/nixin_farm_ssr/assets/views/home/register.html b/nixin_farm_ssr/assets/views/home/register.html new file mode 100644 index 0000000..e69de29 diff --git a/nixin_farm_ssr/assets/views/home/resetpwd.html b/nixin_farm_ssr/assets/views/home/resetpwd.html new file mode 100644 index 0000000..e69de29 diff --git a/nixin_farm_ssr/src/controllers/home.rs b/nixin_farm_ssr/src/controllers/home.rs index ce00300..8740da1 100644 --- a/nixin_farm_ssr/src/controllers/home.rs +++ b/nixin_farm_ssr/src/controllers/home.rs @@ -3,8 +3,40 @@ #![allow(clippy::unused_async)] use loco_rs::prelude::*; use axum::debug_handler; +use axum::{extract::State, Json}; +use loco_rs::{ + app::AppContext, + controller::middleware, + Result, +}; + +use crate::{ + models::users, + views, +}; + +#[debug_handler] +pub async fn home( + //auth: auth::JWT, + ViewEngine(v): ViewEngine, + State(ctx): State, +) -> Result { + //let current_user = users::Model::find_by_pid(&ctx.db, &auth.claims.pid).await; + + // match current_user { + // Ok(user) => { + // views::home::index(&v,&user) + // } + // Err(_) => { + // views::home::login(&v) + // } + // } + + views::home::login(&v) +} pub fn routes() -> Routes { Routes::new() - .prefix("homes") + //.prefix("homes") + .add("/", get(home)) } diff --git a/nixin_farm_ssr/src/views/home.rs b/nixin_farm_ssr/src/views/home.rs new file mode 100644 index 0000000..f59bc05 --- /dev/null +++ b/nixin_farm_ssr/src/views/home.rs @@ -0,0 +1,22 @@ +use loco_rs::prelude::*; + +use crate::models::users; + +/// Display the login form. +/// +/// # Errors +/// +/// When there is an issue with rendering the view. +pub fn login(v: &impl ViewRenderer) -> Result { + format::render().view(v, "home/login.html", data!({})) +} + +/// Display the index page for lged-in user +/// +/// # Errors +/// +/// When there is an issue with rendering the view. +pub fn index(v: &impl ViewRenderer, user: &users::Model) -> Result { + format::render().view(v, "server/show.html", data!({"user": user})) +} + diff --git a/nixin_farm_ssr/src/views/mod.rs b/nixin_farm_ssr/src/views/mod.rs index ae02a00..63a45a1 100644 --- a/nixin_farm_ssr/src/views/mod.rs +++ b/nixin_farm_ssr/src/views/mod.rs @@ -1,6 +1,8 @@ pub mod auth; pub mod user; +pub mod home; + pub mod server; pub mod bundle; pub mod service; \ No newline at end of file