Kaynağa Gözat

Add registration configuration endpoint and enforce registration checks during user registration

Ethanfly 15 saat önce
ebeveyn
işleme
bf54f002c6
1 değiştirilmiş dosya ile 19 ekleme ve 0 silme
  1. 19 0
      server/src/routes/auth.ts

+ 19 - 0
server/src/routes/auth.ts

@@ -8,6 +8,16 @@ import { validateRequest } from '../middleware/validate.js';
 const router = Router();
 const authService = new AuthService();
 
+// 获取注册配置(公开接口)
+router.get('/config', (req, res) => {
+  res.json({
+    success: true,
+    data: {
+      allowRegistration: process.env.ALLOW_REGISTRATION !== 'false',
+    },
+  });
+});
+
 // 登录
 router.post(
   '/login',
@@ -44,6 +54,15 @@ router.post(
     validateRequest,
   ],
   asyncHandler(async (req, res) => {
+    // 检查是否开放注册
+    const allowRegistration = process.env.ALLOW_REGISTRATION !== 'false';
+    if (!allowRegistration) {
+      return res.status(403).json({
+        success: false,
+        message: '注册功能已关闭,请联系管理员',
+      });
+    }
+    
     const { username, password, email, nickname } = req.body;
     
     const result = await authService.register({ username, password, email, nickname });