mirror of
https://github.com/Jackzmc/storage.git
synced 2025-05-08 08:03:21 +00:00
add login form
This commit is contained in:
parent
2773305304
commit
00b55a3536
9 changed files with 48 additions and 31 deletions
|
@ -21,6 +21,7 @@ use crate::managers::repos::RepoManager;
|
||||||
use crate::objs::library::Library;
|
use crate::objs::library::Library;
|
||||||
use crate::util::{setup_logger, JsonErrorResponse, ResponseError};
|
use crate::util::{setup_logger, JsonErrorResponse, ResponseError};
|
||||||
use routes::api;
|
use routes::api;
|
||||||
|
use crate::models::user::UserModel;
|
||||||
use crate::routes::ui;
|
use crate::routes::ui;
|
||||||
|
|
||||||
mod routes;
|
mod routes;
|
||||||
|
@ -39,7 +40,7 @@ const MAX_UPLOAD_SIZE: ByteUnit = ByteUnit::Mebibyte(100_000);
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
struct SessionData {
|
struct SessionData {
|
||||||
user_name: String
|
user: UserModel,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[launch]
|
#[launch]
|
||||||
|
@ -106,6 +107,9 @@ async fn rocket() -> _ {
|
||||||
.mount("/api/library", routes![
|
.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,
|
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![
|
.mount("/", routes![
|
||||||
ui::help::about,
|
ui::help::about,
|
||||||
ui::user::index, ui::user::redirect_list_library_files, ui::user::list_library_files, ui::user::get_library_file,
|
ui::user::index, ui::user::redirect_list_library_files, ui::user::list_library_files, ui::user::get_library_file,
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
|
use rocket::serde::Serialize;
|
||||||
use rocket::serde::uuid::Uuid;
|
use rocket::serde::uuid::Uuid;
|
||||||
use sqlx::query_as;
|
use sqlx::query_as;
|
||||||
use crate::DB;
|
use crate::DB;
|
||||||
use crate::models::repo::RepoModel;
|
use crate::models::repo::RepoModel;
|
||||||
|
|
||||||
|
#[derive(Serialize, Clone, Debug)]
|
||||||
pub struct UserModel {
|
pub struct UserModel {
|
||||||
pub id: Uuid,
|
pub id: Uuid,
|
||||||
pub created_at: NaiveDateTime,
|
pub created_at: NaiveDateTime,
|
||||||
|
|
|
@ -1,2 +1,3 @@
|
||||||
pub mod user;
|
pub mod user;
|
||||||
pub mod help;
|
pub mod help;
|
||||||
|
pub(crate) mod auth;
|
13
server/src/routes/ui/auth.rs
Normal file
13
server/src/routes/ui/auth.rs
Normal 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() })
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ use rocket::serde::json::Json;
|
||||||
use rocket_dyn_templates::{context, Template};
|
use rocket_dyn_templates::{context, Template};
|
||||||
use rocket_session_store::{Session, SessionResult};
|
use rocket_session_store::{Session, SessionResult};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use crate::models::user::UserModel;
|
||||||
use crate::SessionData;
|
use crate::SessionData;
|
||||||
|
|
||||||
#[get("/help/about")]
|
#[get("/help/about")]
|
||||||
|
@ -10,10 +11,15 @@ pub fn about(route: &Route) -> Template {
|
||||||
Template::render("about", context! { route: route.uri.path() })
|
Template::render("about", context! { route: route.uri.path() })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: temp remove when not needed
|
||||||
#[get("/test/set")]
|
#[get("/test/set")]
|
||||||
pub async fn test_set(session: Session<'_, SessionData>) -> &str {
|
pub async fn test_set(session: Session<'_, SessionData>) -> &str {
|
||||||
session.set(SessionData {
|
session.set(SessionData {
|
||||||
user_name: "test".to_string()
|
user: UserModel {
|
||||||
|
id: Default::default(),
|
||||||
|
created_at: Default::default(),
|
||||||
|
name: "Jackie".to_string(),
|
||||||
|
},
|
||||||
}).await;
|
}).await;
|
||||||
"set."
|
"set."
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::util::{JsonErrorResponse, ResponseError};
|
||||||
|
|
||||||
#[get("/")]
|
#[get("/")]
|
||||||
pub async fn index(route: &Route) -> Template {
|
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>")]
|
#[get("/library/<library_id>")]
|
||||||
|
@ -65,6 +65,7 @@ pub async fn list_library_files(route: &Route, libraries: &State<Arc<Mutex<Libra
|
||||||
debug!("segments={:?}", segments);
|
debug!("segments={:?}", segments);
|
||||||
|
|
||||||
Ok(Template::render("libraries", context! {
|
Ok(Template::render("libraries", context! {
|
||||||
|
user: true,
|
||||||
route: route.uri.path(),
|
route: route.uri.path(),
|
||||||
library: library.model(),
|
library: library.model(),
|
||||||
files: files,
|
files: files,
|
||||||
|
|
|
@ -71,4 +71,7 @@ tr.file-list td.filecell-icon .fa-folder {
|
||||||
}
|
}
|
||||||
tr.file-list td.filecell-label a {
|
tr.file-list td.filecell-label a {
|
||||||
color: var(--accent-color);
|
color: var(--accent-color);
|
||||||
|
}
|
||||||
|
.login-bg {
|
||||||
|
background-image: linear-gradient(to top, #fbc2eb 0%, #a6c1ee 100%);
|
||||||
}
|
}
|
|
@ -1,28 +1,11 @@
|
||||||
<!doctype html>
|
{{#> layouts/default }}
|
||||||
<html lang="en">
|
{{> partials/nav }}
|
||||||
<head>
|
<div class="mx-3 columns" style="height: 100%">
|
||||||
<meta charset="utf-8" />
|
<div class="column pl-0 sidebar-column">
|
||||||
<link rel="icon" href="/static/favicon.png" />
|
{{> partials/sidebar }}
|
||||||
|
|
||||||
<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>
|
|
||||||
</div>
|
</div>
|
||||||
</body>
|
<div class="column is-10">
|
||||||
</html>
|
{{> @partial-block }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/layouts/default}}
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<div class="navbar-end">
|
<div class="navbar-end">
|
||||||
|
{{#if user}} <!-- TODO: only show w/ route is library/files -->
|
||||||
<div class="navbar-item" style="width:300px">
|
<div class="navbar-item" style="width:300px">
|
||||||
<div class="field" style="width:100%" >
|
<div class="field" style="width:100%" >
|
||||||
<p class="control has-icons-left">
|
<p class="control has-icons-left">
|
||||||
|
@ -24,6 +25,8 @@
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
{{#if user}}
|
||||||
<div class="navbar-item">
|
<div class="navbar-item">
|
||||||
<a class="icon has-text-black">
|
<a class="icon has-text-black">
|
||||||
<i class="far fa-bell"></i>
|
<i class="far fa-bell"></i>
|
||||||
|
@ -57,5 +60,6 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</nav>
|
</nav>
|
Loading…
Add table
Add a link
Reference in a new issue