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()

View File

@@ -164,6 +164,10 @@ pub enum ErrorType {
FailedValidation {
error: String,
},
OperationFailed,
IncorrectData {
with: String,
},
// ? Voice errors
LiveKitUnavailable,
@@ -188,6 +192,25 @@ pub enum ErrorType {
FeatureDisabled {
feature: String,
},
// ? Authentication
RenderFail,
MissingHeaders,
CaptchaFailed,
BlockedByShield,
UnverifiedAccount,
EmailFailed,
InvalidToken,
MissingInvite,
InvalidInvite,
CompromisedPassword,
ShortPassword,
Blacklisted,
LockedOut,
TotpAlreadyEnabled,
DisallowedMFAMethod,
}
#[macro_export]

View File

@@ -99,6 +99,32 @@ impl<'r> Responder<'r, 'static> for Error {
ErrorType::ImageProcessingFailed => Status::InternalServerError,
ErrorType::NoEmbedData => Status::BadRequest,
ErrorType::VosoUnavailable => Status::BadRequest,
ErrorType::RenderFail => Status::InternalServerError,
ErrorType::MissingHeaders => Status::BadRequest,
ErrorType::CaptchaFailed => Status::BadRequest,
ErrorType::BlockedByShield => Status::BadRequest,
ErrorType::UnverifiedAccount => Status::Forbidden,
ErrorType::EmailFailed => Status::InternalServerError,
ErrorType::InvalidToken => Status::Unauthorized,
ErrorType::MissingInvite => Status::BadRequest,
ErrorType::InvalidInvite => Status::BadRequest,
ErrorType::CompromisedPassword => Status::BadRequest,
ErrorType::ShortPassword => Status::BadRequest,
ErrorType::Blacklisted => {
// Fail blacklisted email addresses.
const RESP: &str = "{\"type\":\"DisallowedContactSupport\", \"note\":\"If you see this messages right here, you're probably doing something you shouldn't be.\"}";
return Response::build()
.status(Status::Unauthorized)
.sized_body(RESP.len(), std::io::Cursor::new(RESP))
.ok();
}
ErrorType::LockedOut => Status::Forbidden,
ErrorType::TotpAlreadyEnabled => Status::BadRequest,
ErrorType::DisallowedMFAMethod => Status::BadRequest,
ErrorType::OperationFailed => Status::InternalServerError,
ErrorType::IncorrectData { .. } => Status::BadRequest,
};
// Serialize the error data structure into JSON.