소스 검색

Add registration configuration endpoint and enforce registration checks during user registration

Ethanfly 11 시간 전
부모
커밋
bf54f002c6
1개의 변경된 파일19개의 추가작업 그리고 0개의 파일을 삭제
  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 });