refactor (v2): better arch

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
2026-06-07 21:19:54 +02:00
parent 0753f3d256
commit 839308ec19
166 changed files with 8553 additions and 884 deletions

View File

@@ -0,0 +1,37 @@
use domain::{
errors::{DomainError, DomainResult},
user::{
entity::User,
value_objects::{Email, Password},
},
};
use super::commands::LoginCommand;
use crate::context::AppContext;
pub async fn execute(ctx: &AppContext, cmd: LoginCommand) -> DomainResult<User> {
let email = Email::new(&cmd.email)?;
let password = Password::new(cmd.password)?;
let user = ctx
.repos
.user
.find_by_email(&email)
.await?
.ok_or_else(|| DomainError::NotFound(format!("user {email}")))?;
let hash = user
.password_hash
.as_ref()
.ok_or_else(|| DomainError::Forbidden("account uses external authentication".into()))?;
if !ctx.services.password_hasher.verify(&password, hash).await? {
return Err(DomainError::Forbidden("invalid credentials".into()));
}
Ok(user)
}
#[cfg(test)]
#[path = "tests/login.rs"]
mod tests;