diff --git a/src/lib.rs b/src/lib.rs index 6c16c13..c3ef877 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,5 +4,5 @@ extern crate justerror; pub mod db; pub mod generic_handlers; pub mod session_store; +pub mod signup; pub(crate) mod templates; -pub mod users; diff --git a/src/login.rs b/src/login.rs new file mode 100644 index 0000000..e69de29 diff --git a/src/main.rs b/src/main.rs index 66c0783..7cc38cc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ use witch_watch::{ db, generic_handlers::{handle_slash, handle_slash_redir}, session_store::SqliteSessionStore, - users::{get_create_user, get_login, handle_signup_success, post_create_user, post_login}, + signup::{get_create_user, get_login, handle_signup_success, post_create_user, post_login}, }; #[tokio::main] diff --git a/src/users.rs b/src/signup.rs similarity index 90% rename from src/users.rs rename to src/signup.rs index 63c46e7..d2d7513 100644 --- a/src/users.rs +++ b/src/signup.rs @@ -20,7 +20,6 @@ use crate::templates::{CreateUser, LoginGet}; const CREATE_QUERY: &str = "insert into witches (id, username, displayname, email, pwhash) values ($1, $2, $3, $4, $5)"; const ID_QUERY: &str = "select * from witches where id = $1"; -// const PW_QUERY: &str = "select pwhash from witches where id = $1"; #[derive(Debug, Default, Clone, PartialEq, Eq, sqlx::FromRow)] pub struct User { @@ -57,9 +56,9 @@ impl AuthUser for User { } } -//-------------------------------------------------------------------------- +//-************************************************************************ // Result types for user creation -//-------------------------------------------------------------------------- +//-************************************************************************ #[derive(Debug, Clone, Template)] #[template(path = "signup_success.html")] @@ -96,9 +95,9 @@ pub enum CreateUserErrorKind { UnknownDBError, } -//-------------------------------------------------------------------------- +//-************************************************************************ // User creation route handlers -//-------------------------------------------------------------------------- +//-************************************************************************ /// Get Handler: displays the form to create a user pub async fn get_create_user() -> CreateUser { @@ -174,13 +173,13 @@ pub async fn post_create_user( Ok(resp) } -/// Get handler for successful signup +/// Generic handler for successful signup pub async fn handle_signup_success( Path(id): Path, State(pool): State, ) -> Response { + let id = id.trim(); let user: User = { - let id = id.trim(); let id = Uuid::try_parse(id).unwrap_or_default(); query_as(ID_QUERY) .bind(id) @@ -196,12 +195,13 @@ pub async fn handle_signup_success( *resp.status_mut() = StatusCode::TEMPORARY_REDIRECT; resp.headers_mut().insert("Location", "/".parse().unwrap()); } + resp } -//-------------------------------------------------------------------------- +//-************************************************************************ // Login error and success types -//-------------------------------------------------------------------------- +//-************************************************************************ #[Error] pub struct LoginError(#[from] LoginErrorKind); @@ -226,9 +226,9 @@ impl IntoResponse for LoginError { } } -//-------------------------------------------------------------------------- +//-************************************************************************ // Login handlers -//-------------------------------------------------------------------------- +//-************************************************************************ /// Handle login queries #[axum::debug_handler] @@ -243,9 +243,9 @@ pub async fn get_login() -> impl IntoResponse { LoginGet::default() } -//------------------------------------------------------------------------- +//-************************************************************************ // private fns -//------------------------------------------------------------------------- +//-************************************************************************ async fn create_user( username: &str,