chore: migrate authifier into codebase (#658)

Co-authored-by: izzy <me@insrt.uk>
Signed-off-by: Zomatree <me@zomatree.live>
Signed-off-by: izzy <me@insrt.uk>
This commit is contained in:
Zomatree
2026-06-21 00:50:06 +01:00
committed by GitHub
parent a7af24b38d
commit d27917b824
145 changed files with 108392 additions and 1189 deletions

View File

@@ -1,4 +1,8 @@
use axum::{http::StatusCode, response::IntoResponse, Json};
use axum::{
http::{header, StatusCode},
response::IntoResponse,
Json,
};
use crate::{Error, ErrorType};
@@ -93,6 +97,29 @@ impl IntoResponse for Error {
ErrorType::FileTypeNotAllowed => StatusCode::BAD_REQUEST,
ErrorType::ImageProcessingFailed => StatusCode::INTERNAL_SERVER_ERROR,
ErrorType::NoEmbedData => StatusCode::BAD_REQUEST,
ErrorType::RenderFail => StatusCode::INTERNAL_SERVER_ERROR,
ErrorType::MissingHeaders => StatusCode::BAD_REQUEST,
ErrorType::CaptchaFailed => StatusCode::BAD_REQUEST,
ErrorType::BlockedByShield => StatusCode::BAD_REQUEST,
ErrorType::UnverifiedAccount => StatusCode::FORBIDDEN,
ErrorType::EmailFailed => StatusCode::INTERNAL_SERVER_ERROR,
ErrorType::InvalidToken => StatusCode::UNAUTHORIZED,
ErrorType::MissingInvite => StatusCode::BAD_REQUEST,
ErrorType::InvalidInvite => StatusCode::BAD_REQUEST,
ErrorType::CompromisedPassword => StatusCode::BAD_REQUEST,
ErrorType::ShortPassword => StatusCode::BAD_REQUEST,
ErrorType::Blacklisted => {
return (
StatusCode::UNAUTHORIZED,
[(header::CONTENT_TYPE, "application/json")],
"{\"type\":\"DisallowedContactSupport\", \"note\":\"If you see this messages right here, you're probably doing something you shouldn't be.\"}"
).into_response()
}
ErrorType::LockedOut => StatusCode::FORBIDDEN,
ErrorType::TotpAlreadyEnabled => StatusCode::BAD_REQUEST,
ErrorType::DisallowedMFAMethod => StatusCode::BAD_REQUEST,
ErrorType::OperationFailed => StatusCode::INTERNAL_SERVER_ERROR,
ErrorType::IncorrectData { .. } => StatusCode::BAD_REQUEST,
};
(status, Json(&self)).into_response()