rename modules for users
This commit is contained in:
parent
41a7abbe13
commit
e5d66769dc
4 changed files with 15 additions and 15 deletions
|
@ -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;
|
||||
|
|
0
src/login.rs
Normal file
0
src/login.rs
Normal file
|
@ -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]
|
||||
|
|
|
@ -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<Uuid> 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<String>,
|
||||
State(pool): State<SqlitePool>,
|
||||
) -> Response {
|
||||
let user: User = {
|
||||
let id = id.trim();
|
||||
let user: User = {
|
||||
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,
|
Loading…
Reference in a new issue