feat: account deletion request and active-user check
This commit is contained in:
@@ -9,6 +9,7 @@ pub const NOT_FOUND: &str = "NOT_FOUND";
|
||||
pub const INVALID_INPUT: &str = "INVALID_INPUT";
|
||||
pub const UNAUTHORIZED: &str = "UNAUTHORIZED";
|
||||
pub const FORBIDDEN: &str = "FORBIDDEN";
|
||||
pub const CONFLICT: &str = "CONFLICT";
|
||||
pub const RATE_LIMITED: &str = "RATE_LIMITED";
|
||||
pub const INTERNAL: &str = "INTERNAL";
|
||||
|
||||
@@ -32,6 +33,7 @@ pub fn domain_error_status(e: &DomainError) -> StatusCode {
|
||||
DomainError::NotFound(_) => StatusCode::NOT_FOUND,
|
||||
DomainError::Unauthorized(_) => StatusCode::UNAUTHORIZED,
|
||||
DomainError::Forbidden(_) => StatusCode::FORBIDDEN,
|
||||
DomainError::Conflict(_) => StatusCode::CONFLICT,
|
||||
DomainError::InfrastructureError(_) => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
}
|
||||
}
|
||||
@@ -64,6 +66,7 @@ impl IntoResponse for ApiError {
|
||||
DomainError::NotFound(_) => refuse(status, NOT_FOUND, self.0.to_string()),
|
||||
DomainError::Unauthorized(_) => refuse(status, UNAUTHORIZED, self.0.to_string()),
|
||||
DomainError::Forbidden(_) => refuse(status, FORBIDDEN, self.0.to_string()),
|
||||
DomainError::Conflict(_) => refuse(status, CONFLICT, self.0.to_string()),
|
||||
DomainError::InfrastructureError(_) => {
|
||||
tracing::error!("Internal error: {:?}", self.0);
|
||||
refuse(status, INTERNAL, "internal server error")
|
||||
|
||||
@@ -8,6 +8,11 @@ use axum::{
|
||||
};
|
||||
use domain::{errors::DomainError, value_objects::UserId};
|
||||
|
||||
async fn ensure_active(state: &AppState, user_id: &UserId) -> Result<(), DomainError> {
|
||||
application::users::ensure_active::execute(&state.app_ctx.deps.users.ensure_active, user_id)
|
||||
.await
|
||||
}
|
||||
|
||||
use crate::{errors::ApiError, state::AppState};
|
||||
|
||||
pub struct AuthenticatedUser(pub UserId);
|
||||
@@ -37,6 +42,7 @@ where
|
||||
.auth
|
||||
.validate_token(token)
|
||||
.await?;
|
||||
ensure_active(&app_state, &user_id).await?;
|
||||
Ok(AuthenticatedUser(user_id))
|
||||
}
|
||||
}
|
||||
@@ -75,6 +81,10 @@ where
|
||||
.validate_token(&token)
|
||||
.await
|
||||
.ok();
|
||||
let user_id = match user_id {
|
||||
Some(id) if ensure_active(&app_state, &id).await.is_ok() => Some(id),
|
||||
_ => None,
|
||||
};
|
||||
Ok(OptionalCookieUser(user_id))
|
||||
}
|
||||
}
|
||||
@@ -97,6 +107,14 @@ where
|
||||
.validate_token(&token)
|
||||
.await
|
||||
.map_err(|_| Redirect::to("/login").into_response())?;
|
||||
ensure_active(&app_state, &user_id)
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
DomainError::InfrastructureError(_) => {
|
||||
StatusCode::INTERNAL_SERVER_ERROR.into_response()
|
||||
}
|
||||
_ => Redirect::to("/login").into_response(),
|
||||
})?;
|
||||
Ok(RequiredCookieUser(user_id))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user