add login form

This commit is contained in:
Jackzie 2025-04-15 19:08:18 -05:00
parent 2773305304
commit 00b55a3536
9 changed files with 48 additions and 31 deletions

View file

@ -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,

View file

@ -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,

View file

@ -1,2 +1,3 @@
pub mod user;
pub mod help;
pub mod help;
pub(crate) mod auth;

View file

@ -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() })
}

View file

@ -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."
}

View file

@ -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/<library_id>")]
@ -65,6 +65,7 @@ pub async fn list_library_files(route: &Route, libraries: &State<Arc<Mutex<Libra
debug!("segments={:?}", segments);
Ok(Template::render("libraries", context! {
user: true,
route: route.uri.path(),
library: library.model(),
files: files,

View file

@ -71,4 +71,7 @@ tr.file-list td.filecell-icon .fa-folder {
}
tr.file-list td.filecell-label a {
color: var(--accent-color);
}
.login-bg {
background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);
}

View file

@ -1,28 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="/static/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>storage-app</title>
<!-- TODO: use static -->
<link href="/static/css/main.css" rel="stylesheet" />
<link rel="stylesheet" href="/static/css/bulma.min.css">
<link href="/static/icons/css/fontawesome.css" rel="stylesheet" />
<link href="/static/icons/css/solid.css" rel="stylesheet" />
<link href="/static/icons/css/regular.css" rel="stylesheet" />
<link href="/static/icons/css/brands.css" rel="stylesheet" />
</head>
<body>
{{> partials/nav }}
<div class="mx-3 columns" style="height: 100%">
<div class="column pl-0 sidebar-column">
{{> partials/sidebar }}
</div>
<div class="column is-10">
{{> @partial-block }}
</div>
{{#> layouts/default }}
{{> partials/nav }}
<div class="mx-3 columns" style="height: 100%">
<div class="column pl-0 sidebar-column">
{{> partials/sidebar }}
</div>
</body>
</html>
<div class="column is-10">
{{> @partial-block }}
</div>
</div>
{{/layouts/default}}

View file

@ -14,6 +14,7 @@
</div>
<div class="navbar-end">
{{#if user}} <!-- TODO: only show w/ route is library/files -->
<div class="navbar-item" style="width:300px">
<div class="field" style="width:100%" >
<p class="control has-icons-left">
@ -24,6 +25,8 @@
</p>
</div>
</div>
{{/if}}
{{#if user}}
<div class="navbar-item">
<a class="icon has-text-black">
<i class="far fa-bell"></i>
@ -57,5 +60,6 @@
</div>
</div>
{{/if}}
</div>
</nav>