feat: 新增环境变量DISABLE_REGISTRATION控制用户注册开关

This commit is contained in:
wizardchen
2025-12-22 14:41:11 +08:00
committed by lyingbug
parent d6c3636b20
commit a36bf67166
3 changed files with 15 additions and 1 deletions
+10
View File
@@ -2,6 +2,7 @@ package handler
import (
"net/http"
"os"
"strings"
"github.com/gin-gonic/gin"
@@ -47,12 +48,21 @@ func NewAuthHandler(configInfo *config.Config,
// @Param request body types.RegisterRequest true "注册请求参数"
// @Success 201 {object} types.RegisterResponse
// @Failure 400 {object} errors.AppError "请求参数错误"
// @Failure 403 {object} errors.AppError "注册功能已禁用"
// @Router /auth/register [post]
func (h *AuthHandler) Register(c *gin.Context) {
ctx := c.Request.Context()
logger.Info(ctx, "Start user registration")
// 通过环境变量 DISABLE_REGISTRATION=true 禁止注册
if os.Getenv("DISABLE_REGISTRATION") == "true" {
logger.Warn(ctx, "Registration is disabled by DISABLE_REGISTRATION env")
appErr := errors.NewForbiddenError("Registration is disabled")
c.Error(appErr)
return
}
var req types.RegisterRequest
if err := c.ShouldBindJSON(&req); err != nil {
logger.Error(ctx, "Failed to parse registration request parameters", err)