more cleanup

This commit is contained in:
Joe Ardent 2023-05-18 12:24:43 -07:00
parent 46232b4254
commit 79ecd74500
1 changed files with 7 additions and 3 deletions

View File

@ -8,7 +8,6 @@ use axum::{
response::IntoResponse, response::IntoResponse,
}; };
use sqlx::SqlitePool; use sqlx::SqlitePool;
use tracing::log::log;
use unicode_segmentation::UnicodeSegmentation; use unicode_segmentation::UnicodeSegmentation;
use uuid::Uuid; use uuid::Uuid;
@ -17,6 +16,7 @@ use crate::templates::CreateUser;
const CREATE_QUERY: &str = const CREATE_QUERY: &str =
"insert into witches (id, username, displayname, email, pwhash) values ($1, $2, $3, $4, $5)"; "insert into witches (id, username, displayname, email, pwhash) values ($1, $2, $3, $4, $5)";
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct User { pub struct User {
id: Uuid, id: Uuid,
username: String, username: String,
@ -45,13 +45,16 @@ impl From<DbUser> for User {
} }
} }
/// Get Handler: displays the form to create a user
pub async fn get_create_user() -> CreateUser { pub async fn get_create_user() -> CreateUser {
CreateUser::default() CreateUser::default()
} }
/// Post Handler: validates form values and calls the actual, private user
/// creation function
#[axum::debug_handler] #[axum::debug_handler]
pub async fn post_create_user( pub async fn post_create_user(
State(pool): State<sqlx::SqlitePool>, State(pool): State<SqlitePool>,
Form(signup): Form<CreateUser>, Form(signup): Form<CreateUser>,
) -> Result<(), CreateUserError> { ) -> Result<(), CreateUserError> {
let username = &signup.username; let username = &signup.username;
@ -97,7 +100,8 @@ pub async fn post_create_user(
}; };
let email = &email; let email = &email;
let _ = create_user(username, displayname, email, password, &pool).await?; let user = create_user(username, displayname, email, password, &pool).await?;
tracing::debug!("created {user:?}");
Ok(()) Ok(())
} }