mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-17 19:35:38 +00:00
feat(web): add --disable-registration flag to disable user registration (#1881)
This commit is contained in:
@@ -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((
|
||||
|
||||
Reference in New Issue
Block a user