Work on config and settings UI

This commit is contained in:
Jackzie 2025-04-20 12:41:38 -05:00
parent d1cf5d3038
commit 4693a6c599
9 changed files with 1000 additions and 33 deletions

4
.gitignore vendored
View file

@ -1,4 +1,4 @@
**/.idea
target
config
.env
config.toml
.env

871
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -22,4 +22,5 @@ humanize-bytes = "1.0.6"
rocket-session-store = "0.2.1"
uuid = { version = "1.16.0", features = ["v4"] }
rand = { version = "0.9.0", features = ["thread_rng"] }
bcrypt = "0.17.0"
bcrypt = "0.17.0"
openidconnect = "4.0.0"

16
config.sample.toml Normal file
View file

@ -0,0 +1,16 @@
[general]
listen_ip = "0.0.0.0"
listen_port = 80
[backends.local]
path = "/var/tmp/test"
[auth]
enable_registration = true
openid_enabled = true
# Where the .well-known/openid-configuration exists
openid_issuer_url = "https://accounts.example.com"
openid_client_id = ""
openid_client_secret = ""
[smtp]
# TODO:

View file

@ -1,12 +0,0 @@
[general]
listen_ip = "0.0.0.0"
listen_port = 80
[backends.local]
path = "/var/tmp/test"
[auth]
enable_registration = true
[smtp]
# TODO:

27
src/config.rs Normal file
View file

@ -0,0 +1,27 @@
use rocket::serde::{Serialize,Deserialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
general: GeneralConfig,
auth: AuthConfig,
smtp: EmailConfig
}
#[derive(Debug, Serialize, Deserialize)]
pub struct GeneralConfig {
pub listen_ip: Option<String>,
pub listen_port: Option<u32>
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AuthConfig {
pub disable_registration: bool,
pub openid_enabled: Option<bool>,
pub openid_issuer_url: Option<String>,
pub openid_client_id: Option<String>,
pub openid_client_secret: Option<String>
}
#[derive(Debug, Serialize, Deserialize)]
pub struct EmailConfig {
}

View file

@ -39,6 +39,7 @@ mod objs;
mod helpers;
mod consts;
mod guards;
mod config;
pub type DB = Pool<Postgres>;
@ -145,7 +146,7 @@ async fn rocket() -> _ {
ui::auth::forgot_password::page, ui::auth::forgot_password::handler,
])
.mount("/", routes![
ui::user::index, ui::user::redirect_list_library_files, ui::user::list_library_files, ui::user::get_library_file,
ui::user::user_settings, ui::user::index, ui::user::redirect_list_library_files, ui::user::list_library_files, ui::user::get_library_file,
])
.mount("/", routes![
ui::help::about,

View file

@ -21,7 +21,10 @@ use crate::objs::library::ListOptions;
use crate::routes::ui::auth;
use crate::util::{JsonErrorResponse, ResponseError};
#[get("/settings")]
pub async fn user_settings(user: AuthUser, route: &Route) -> Template {
Template::render("settings", context! { session: user.session, route: route.uri.path() })
}
#[get("/")]
pub async fn index(user: AuthUser, route: &Route) -> Template {
Template::render("index", context! { session: user.session, route: route.uri.path(), test: "value" })

View file

@ -0,0 +1,92 @@
{{#> layouts/main body-class="" }}
<div class="columns">
<div class="column">
<div class="box is-radiusless" id="account">
<h4 class="title is-4 has-text-link">Account Settings</h4>
<form method="post" action="/settings/account">
<input type="hidden" name="_csrf" value="{{ csrf_token }}">
<div class="field">
<label class="label">Name</label>
<div class="control has-icons-left">
<input autofocus required name="username" value="{{ session.user.name }}"
class="input {{#if errors.name}}is-danger{{/if}}" type="text" placeholder="Name">
<span class="icon is-small is-left">
<i class="fas fa-user"></i>
</span>
</div>
{{#if errors.name }}
<p class="help is-danger">{{errors.name}}</p>
{{/if}}
</div>
<div class="field">
<label class="label">Password</label>
<div class="control">
<a class="button is-small">Reset password</a>
</div>
</div>
<br>
<div class="buttons">
<button class="button is-success" type="submit">Save Changes</button>
</div>
</form>
</div>
<div class="box is-radiusless" id="account">
<h4 class="title is-4 has-text-link">UI Preferences</h4>
<form method="post" action="/settings/ui">
<input type="hidden" name="_csrf" value="{{ csrf_token }}">
<div class="field">
<label class="label">Language</label>
<div class="control">
<div class="select">
<select>
<option selected value="en-us">English</option>
</select>
</div>
</div>
</div>
<br>
<div class="buttons">
<button class="button is-success" type="submit">Save Changes</button>
</div>
</form>
</div>
<div class="box is-radiusless" id="sessions">
<h4 class="title is-4 has-text-link">Active Sessions</h4>
<table class="table is-fullwidth">
<thead>
<tr>
<th>Id</th>
<th>IP</th>
<th>Location</th>
<th>Last Active</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>UUID</td>
<td>IP</td>
<td>Location</td>
<td>Now</td>
<td><em>current</em></td>
</tr>
</tb>
</table>
<br>
</div>
</div>
<div class="column is-3">
<div class="box">
<aside class="sidebar pl-0 mb-0">
<p class="sidebar-header">Sections</p>
<ul class="sidebar-list mb-0">
<li><a href="#account"><i class="fa fa-user"></i>Account</a></li>
<li><a href="#ui"><i class="fa fa-cog"></i>UI Preferences</a></li>
<li><a href="#sessions"><i class="fa fa-laptop"></i>Active Sessions</a></li>
</ul>
</aside>
</div>
</div>
</div>
{{/layouts/main}}