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 db;
|
||||||
pub mod generic_handlers;
|
pub mod generic_handlers;
|
||||||
pub mod session_store;
|
pub mod session_store;
|
||||||
|
pub mod signup;
|
||||||
pub(crate) mod templates;
|
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,
|
db,
|
||||||
generic_handlers::{handle_slash, handle_slash_redir},
|
generic_handlers::{handle_slash, handle_slash_redir},
|
||||||
session_store::SqliteSessionStore,
|
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]
|
#[tokio::main]
|
||||||
|
|
|
@ -20,7 +20,6 @@ use crate::templates::{CreateUser, LoginGet};
|
||||||
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)";
|
||||||
const ID_QUERY: &str = "select * from witches where id = $1";
|
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)]
|
#[derive(Debug, Default, Clone, PartialEq, Eq, sqlx::FromRow)]
|
||||||
pub struct User {
|
pub struct User {
|
||||||
|
@ -57,9 +56,9 @@ impl AuthUser<Uuid> for User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
// Result types for user creation
|
// Result types for user creation
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
|
|
||||||
#[derive(Debug, Clone, Template)]
|
#[derive(Debug, Clone, Template)]
|
||||||
#[template(path = "signup_success.html")]
|
#[template(path = "signup_success.html")]
|
||||||
|
@ -96,9 +95,9 @@ pub enum CreateUserErrorKind {
|
||||||
UnknownDBError,
|
UnknownDBError,
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
// User creation route handlers
|
// User creation route handlers
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
|
|
||||||
/// Get Handler: displays the form to create a user
|
/// Get Handler: displays the form to create a user
|
||||||
pub async fn get_create_user() -> CreateUser {
|
pub async fn get_create_user() -> CreateUser {
|
||||||
|
@ -174,13 +173,13 @@ pub async fn post_create_user(
|
||||||
Ok(resp)
|
Ok(resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get handler for successful signup
|
/// Generic handler for successful signup
|
||||||
pub async fn handle_signup_success(
|
pub async fn handle_signup_success(
|
||||||
Path(id): Path<String>,
|
Path(id): Path<String>,
|
||||||
State(pool): State<SqlitePool>,
|
State(pool): State<SqlitePool>,
|
||||||
) -> Response {
|
) -> Response {
|
||||||
|
let id = id.trim();
|
||||||
let user: User = {
|
let user: User = {
|
||||||
let id = id.trim();
|
|
||||||
let id = Uuid::try_parse(id).unwrap_or_default();
|
let id = Uuid::try_parse(id).unwrap_or_default();
|
||||||
query_as(ID_QUERY)
|
query_as(ID_QUERY)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
|
@ -196,12 +195,13 @@ pub async fn handle_signup_success(
|
||||||
*resp.status_mut() = StatusCode::TEMPORARY_REDIRECT;
|
*resp.status_mut() = StatusCode::TEMPORARY_REDIRECT;
|
||||||
resp.headers_mut().insert("Location", "/".parse().unwrap());
|
resp.headers_mut().insert("Location", "/".parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
resp
|
resp
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
// Login error and success types
|
// Login error and success types
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
|
|
||||||
#[Error]
|
#[Error]
|
||||||
pub struct LoginError(#[from] LoginErrorKind);
|
pub struct LoginError(#[from] LoginErrorKind);
|
||||||
|
@ -226,9 +226,9 @@ impl IntoResponse for LoginError {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
// Login handlers
|
// Login handlers
|
||||||
//--------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
|
|
||||||
/// Handle login queries
|
/// Handle login queries
|
||||||
#[axum::debug_handler]
|
#[axum::debug_handler]
|
||||||
|
@ -243,9 +243,9 @@ pub async fn get_login() -> impl IntoResponse {
|
||||||
LoginGet::default()
|
LoginGet::default()
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
// private fns
|
// private fns
|
||||||
//-------------------------------------------------------------------------
|
//-************************************************************************
|
||||||
|
|
||||||
async fn create_user(
|
async fn create_user(
|
||||||
username: &str,
|
username: &str,
|
Loading…
Reference in a new issue