2024-10-03 15:55:38 -04:00
|
|
|
use axum::{
|
|
|
|
debug_handler,
|
2024-10-05 08:09:46 -04:00
|
|
|
extract::State,
|
2024-10-03 15:55:38 -04:00
|
|
|
response::{IntoResponse, Response},
|
2024-10-05 08:09:46 -04:00
|
|
|
Json,
|
2024-10-03 15:55:38 -04:00
|
|
|
};
|
2024-10-05 08:09:46 -04:00
|
|
|
use tracing::debug;
|
2024-10-03 15:55:38 -04:00
|
|
|
|
2024-10-05 08:09:46 -04:00
|
|
|
use crate::{
|
|
|
|
db::{get_username_and_password_by_username, DbPool, UserIdAndHashedPassword},
|
|
|
|
models::AppError,
|
|
|
|
requests::AppState,
|
|
|
|
services::verify_password,
|
|
|
|
};
|
|
|
|
|
|
|
|
use super::models::AuthLoginRequest;
|
2024-10-03 15:55:38 -04:00
|
|
|
|
|
|
|
#[debug_handler]
|
2024-10-05 08:09:46 -04:00
|
|
|
pub async fn auth_login_post_handler(
|
|
|
|
State(state): State<AppState>,
|
|
|
|
Json(body): Json<AuthLoginRequest>,
|
|
|
|
) -> Result<Response, AppError> {
|
|
|
|
let pool = state.db_pool();
|
|
|
|
auth_login_request(pool, body).await
|
|
|
|
}
|
|
|
|
|
|
|
|
async fn auth_login_request(pool: &DbPool, body: AuthLoginRequest) -> Result<Response, AppError> {
|
|
|
|
debug!(?body);
|
|
|
|
|
|
|
|
let AuthLoginRequest { username, password } = body;
|
|
|
|
let UserIdAndHashedPassword {
|
|
|
|
id: _id,
|
|
|
|
password: hashed_password,
|
|
|
|
} = get_username_and_password_by_username(pool, username).await?;
|
|
|
|
|
|
|
|
verify_password(password, hashed_password)?;
|
|
|
|
|
2024-10-03 15:55:38 -04:00
|
|
|
Ok(().into_response())
|
|
|
|
}
|