From 59058207f4593650f98f3d228c94ed76f9bb17e6 Mon Sep 17 00:00:00 2001 From: Matthew Pomes Date: Thu, 2 Jul 2026 21:59:01 -0500 Subject: [PATCH] Switch to git dep so build system will work --- Cargo.lock | 6 ++++++ Cargo.toml | 21 ++++++++++++++++++--- src/admin.rs | 13 +++++++------ src/auth.rs | 9 +++++---- src/devices.rs | 4 ++-- templates/password_updated.html.tera | 8 ++++++++ 6 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 templates/password_updated.html.tera diff --git a/Cargo.lock b/Cargo.lock index e6ba48e..7074cf7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2272,6 +2272,7 @@ dependencies = [ [[package]] name = "rocket" version = "0.6.0-dev" +source = "git+https://github.com/the10thWiz/Rocket.git?rev=ecceb93ba65d91dcf214000fa648d69cd74b95fb#ecceb93ba65d91dcf214000fa648d69cd74b95fb" dependencies = [ "async-stream", "async-trait", @@ -2321,6 +2322,7 @@ dependencies = [ [[package]] name = "rocket_codegen" version = "0.6.0-dev" +source = "git+https://github.com/the10thWiz/Rocket.git?rev=ecceb93ba65d91dcf214000fa648d69cd74b95fb#ecceb93ba65d91dcf214000fa648d69cd74b95fb" dependencies = [ "devise", "glob", @@ -2336,6 +2338,7 @@ dependencies = [ [[package]] name = "rocket_db_pools" version = "0.1.0" +source = "git+https://github.com/the10thWiz/Rocket.git?rev=ecceb93ba65d91dcf214000fa648d69cd74b95fb#ecceb93ba65d91dcf214000fa648d69cd74b95fb" dependencies = [ "log", "rocket", @@ -2347,6 +2350,7 @@ dependencies = [ [[package]] name = "rocket_db_pools_codegen" version = "0.1.0" +source = "git+https://github.com/the10thWiz/Rocket.git?rev=ecceb93ba65d91dcf214000fa648d69cd74b95fb#ecceb93ba65d91dcf214000fa648d69cd74b95fb" dependencies = [ "devise", "quote", @@ -2355,6 +2359,7 @@ dependencies = [ [[package]] name = "rocket_dyn_templates" version = "0.1.0" +source = "git+https://github.com/the10thWiz/Rocket.git?rev=ecceb93ba65d91dcf214000fa648d69cd74b95fb#ecceb93ba65d91dcf214000fa648d69cd74b95fb" dependencies = [ "normpath", "notify", @@ -2366,6 +2371,7 @@ dependencies = [ [[package]] name = "rocket_http" version = "0.6.0-dev" +source = "git+https://github.com/the10thWiz/Rocket.git?rev=ecceb93ba65d91dcf214000fa648d69cd74b95fb#ecceb93ba65d91dcf214000fa648d69cd74b95fb" dependencies = [ "cookie", "either", diff --git a/Cargo.toml b/Cargo.toml index da8c429..bb72373 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,12 +6,27 @@ edition = "2024" [dependencies] base64 = "0.22.1" chrono = { version = "0.4.41", features = ["serde"] } -rocket = { path = "../rocket/core/lib", features = ["json", "tls", "secrets"] } -rocket_dyn_templates = { path = "../rocket/contrib/dyn_templates", features = ["tera"] } -rocket_db_pools = { path = "../rocket/contrib/db_pools/lib", features = ["sqlx_sqlite", "sqlx_macros"] } sqlx = "*" semver = { version = "1.0.26", features = ["serde"] } password-hash = { version = "0.5.0", features = ["std"] } argon2 = { version = "0.5.3", features = ["std"] } lazy_static = "1.5.0" either = "1.15.0" + +[dependencies.rocket] +# path = "../rocket/core/lib" +git = "https://github.com/the10thWiz/Rocket.git" +rev = "ecceb93ba65d91dcf214000fa648d69cd74b95fb" +features = ["json", "tls", "secrets"] + +[dependencies.rocket_dyn_templates] +# path = "../rocket/contrib/dyn_templates" +git = "https://github.com/the10thWiz/Rocket.git" +rev = "ecceb93ba65d91dcf214000fa648d69cd74b95fb" +features = ["tera"] + +[dependencies.rocket_db_pools] +# path = "../rocket/contrib/db_pools/lib" +git = "https://github.com/the10thWiz/Rocket.git" +rev = "ecceb93ba65d91dcf214000fa648d69cd74b95fb" +features = ["sqlx_sqlite", "sqlx_macros"] diff --git a/src/admin.rs b/src/admin.rs index b9a6e4d..95f5cb2 100644 --- a/src/admin.rs +++ b/src/admin.rs @@ -115,12 +115,13 @@ impl<'r> FromRequest<'r> for InitialSetup { .await .map_error(|_| InitialSetupError::InternalError) ); - let user_count = try_outcome!( - sqlx::query!("SELECT count(name) as count from users") - .fetch_one(&mut **db) - .await - .into() - ); + let user_count = match sqlx::query!("SELECT count(name) as count from users") + .fetch_one(&mut **db) + .await + { + Ok(v) => v, + Err(e) => return Outcome::Error(e.into()), + }; if user_count.count == 0 { Outcome::Success(Self) } else { diff --git a/src/auth.rs b/src/auth.rs index dc52e20..42bc021 100644 --- a/src/auth.rs +++ b/src/auth.rs @@ -4,7 +4,7 @@ use argon2::{Argon2, PasswordVerifier}; use base64::{DecodeError, Engine, alphabet::STANDARD, engine::GeneralPurposeConfig}; use password_hash::{PasswordHash, PasswordHasher, SaltString, rand_core::OsRng}; use rocket::{ - async_trait, catch, catchers, form::Form, http::{CookieJar, Status}, post, request::{FromRequest, Outcome}, response::Redirect, routes, serde::{Deserialize, Serialize}, trace::debug, uri, Catcher, FromForm, Request, Route, TypedError + async_trait, catch, catchers, form::Form, http::{CookieJar, Status}, post, request::{FromRequest, Outcome}, response::{content::RawHtml, Redirect}, routes, serde::{Deserialize, Serialize}, trace::debug, uri, Catcher, FromForm, Request, Route, TypedError }; use rocket_db_pools::Connection; use rocket_dyn_templates::{context, Template}; @@ -15,6 +15,7 @@ pub struct BasicAuth { username: String, is_admin: bool, } + #[derive(Debug, TypedError)] pub enum Unauthorized { #[error(status = 401)] @@ -172,17 +173,17 @@ pub async fn update_password( auth: BasicAuth, pw: Form>, mut db: Connection, -) -> Result<&'static str, SqlError> { +) -> Result { let salt = SaltString::generate(&mut OsRng); let pw_hash = Argon2::default() .hash_password(pw.password.as_bytes(), salt.as_salt()) .expect("Failed to hash password"); - sqlx::query("INSERT INTO users (name, password) VALUES (?1, ?2) ON CONFLICT DO UPDATE SET password = ?2") + sqlx::query("UPDATE users SET password = ?2 WHERE name = ?1") .bind(auth.username) .bind(pw_hash.to_string()) .execute(&mut **db) .await?; - Ok("") + Ok(Template::render("password_updated", context!{})) } #[derive(Debug, Serialize, Deserialize, FromForm)] diff --git a/src/devices.rs b/src/devices.rs index dc62585..a8171b8 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -6,9 +6,9 @@ use crate::{ directory::{Episode, Podcast}, }; use rocket::{ - Route, TypedError, get, post, routes, + Route, get, post, routes, serde::{Deserialize, Serialize, json::Json}, - trace::{debug, info}, + trace::{debug}, }; use rocket_db_pools::{ Connection, diff --git a/templates/password_updated.html.tera b/templates/password_updated.html.tera new file mode 100644 index 0000000..2db77cc --- /dev/null +++ b/templates/password_updated.html.tera @@ -0,0 +1,8 @@ +{% extends "_layout" %} + +{% block content %} +
+

Password successfully updated

+ Home +
+{% endblock content %}