feat(web): add --disable-registration flag to disable user registration (#1881)

This commit is contained in:
Mg Pig
2026-02-13 16:03:11 +08:00
committed by GitHub
parent 011770a601
commit 3512a80597
4 changed files with 37 additions and 4 deletions
+18 -1
View File
@@ -14,6 +14,13 @@ use super::{
AppStateInner,
};
/// Feature flags for the web server
#[derive(Clone, Default)]
pub struct FeatureFlags {
/// Whether user registration is disabled
pub disable_registration: bool,
}
#[derive(Debug, Deserialize, Serialize)]
pub struct LoginResult {
messages: Vec<Message>,
@@ -67,7 +74,7 @@ mod put {
}
mod post {
use axum::Json;
use axum::{extract::Extension, Json};
use easytier::proto::common::Void;
use crate::restful::{
@@ -110,10 +117,20 @@ mod post {
}
pub async fn register(
Extension(feature_flags): Extension<FeatureFlags>,
auth_session: AuthSession,
captcha_session: tower_sessions::Session,
Json(req): Json<RegisterNewUser>,
) -> Result<Json<Void>, HttpHandleError> {
// Check if registration is disabled
if feature_flags.disable_registration {
tracing::warn!("Registration attempt blocked: registration is disabled");
return Err((
StatusCode::FORBIDDEN,
other_error("Registration is disabled").into(),
));
}
// 调用CaptchaUtil的静态方法验证验证码是否正确
if !CaptchaUtil::ver(&req.captcha, &captcha_session).await {
return Err((