diff --git a/server/src/main.rs b/server/src/main.rs index 8dddd2f..6a33e85 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -21,6 +21,7 @@ use crate::managers::repos::RepoManager; use crate::objs::library::Library; use crate::util::{setup_logger, JsonErrorResponse, ResponseError}; use routes::api; +use crate::models::user::UserModel; use crate::routes::ui; mod routes; @@ -39,7 +40,7 @@ const MAX_UPLOAD_SIZE: ByteUnit = ByteUnit::Mebibyte(100_000); #[derive(Clone, Debug, Serialize)] struct SessionData { - user_name: String + user: UserModel, } #[launch] @@ -106,6 +107,9 @@ async fn rocket() -> _ { .mount("/api/library", routes![ api::library::move_file, api::library::upload_file, api::library::download_file, api::library::list_files, api::library::get_file, api::library::delete_file, ]) + .mount("/auth", routes![ + ui::auth::login + ]) .mount("/", routes![ ui::help::about, ui::user::index, ui::user::redirect_list_library_files, ui::user::list_library_files, ui::user::get_library_file, diff --git a/server/src/models/user.rs b/server/src/models/user.rs index 09493fe..0ba0969 100644 --- a/server/src/models/user.rs +++ b/server/src/models/user.rs @@ -1,9 +1,11 @@ use chrono::NaiveDateTime; +use rocket::serde::Serialize; use rocket::serde::uuid::Uuid; use sqlx::query_as; use crate::DB; use crate::models::repo::RepoModel; +#[derive(Serialize, Clone, Debug)] pub struct UserModel { pub id: Uuid, pub created_at: NaiveDateTime, diff --git a/server/src/routes/ui.rs b/server/src/routes/ui.rs index 3abdb02..cf27f27 100644 --- a/server/src/routes/ui.rs +++ b/server/src/routes/ui.rs @@ -1,2 +1,3 @@ pub mod user; -pub mod help; \ No newline at end of file +pub mod help; +pub(crate) mod auth; \ No newline at end of file diff --git a/server/src/routes/ui/auth.rs b/server/src/routes/ui/auth.rs new file mode 100644 index 0000000..be532b5 --- /dev/null +++ b/server/src/routes/ui/auth.rs @@ -0,0 +1,13 @@ +use rocket::{get, post, Route}; +use rocket_dyn_templates::{context, Template}; + +#[get("/login")] +pub async fn login(route: &Route) -> Template { + Template::render("auth/login", context! { route: route.uri.path() }) + +} +#[post("/login")] +pub async fn login_handler(route: &Route) -> Template { + Template::render("auth/login", context! { route: route.uri.path() }) + +} \ No newline at end of file diff --git a/server/src/routes/ui/help.rs b/server/src/routes/ui/help.rs index ce89ce0..6b7fb63 100644 --- a/server/src/routes/ui/help.rs +++ b/server/src/routes/ui/help.rs @@ -3,6 +3,7 @@ use rocket::serde::json::Json; use rocket_dyn_templates::{context, Template}; use rocket_session_store::{Session, SessionResult}; use serde::Serialize; +use crate::models::user::UserModel; use crate::SessionData; #[get("/help/about")] @@ -10,10 +11,15 @@ pub fn about(route: &Route) -> Template { Template::render("about", context! { route: route.uri.path() }) } +// TODO: temp remove when not needed #[get("/test/set")] pub async fn test_set(session: Session<'_, SessionData>) -> &str { session.set(SessionData { - user_name: "test".to_string() + user: UserModel { + id: Default::default(), + created_at: Default::default(), + name: "Jackie".to_string(), + }, }).await; "set." } diff --git a/server/src/routes/ui/user.rs b/server/src/routes/ui/user.rs index a3b2dfa..8278f3e 100644 --- a/server/src/routes/ui/user.rs +++ b/server/src/routes/ui/user.rs @@ -18,7 +18,7 @@ use crate::util::{JsonErrorResponse, ResponseError}; #[get("/")] pub async fn index(route: &Route) -> Template { - Template::render("index", context! { route: route.uri.path(), test: "value" }) + Template::render("index", context! { user: true, route: route.uri.path(), test: "value" }) } #[get("/library/")] @@ -65,6 +65,7 @@ pub async fn list_library_files(route: &Route, libraries: &State - - - - - - - storage-app - - - - - - - - - - {{> partials/nav }} -
- -
- {{> @partial-block }} -
+{{#> layouts/default }} + {{> partials/nav }} +
+ - - +
+ {{> @partial-block }} +
+
+{{/layouts/default}} \ No newline at end of file diff --git a/server/templates/partials/nav.html.hbs b/server/templates/partials/nav.html.hbs index 63079a1..039b7a2 100644 --- a/server/templates/partials/nav.html.hbs +++ b/server/templates/partials/nav.html.hbs @@ -14,6 +14,7 @@
+ {{/if}} \ No newline at end of file