提交
This commit is contained in:
@@ -2,12 +2,7 @@ const express = require('express');
|
||||
const crypto = require('crypto');
|
||||
const router = express.Router();
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* tags:
|
||||
* name: Captcha
|
||||
* description: 验证码API
|
||||
*/
|
||||
|
||||
|
||||
// 内存存储验证码(生产环境建议使用Redis)
|
||||
|
||||
@@ -107,35 +102,7 @@ function generateCaptchaSVG(text) {
|
||||
return svg;
|
||||
}
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /captcha/generate:
|
||||
* get:
|
||||
* summary: 生成图形验证码
|
||||
* tags: [Captcha]
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 成功生成验证码
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* example: true
|
||||
* data:
|
||||
* type: object
|
||||
* properties:
|
||||
* captchaId:
|
||||
* type: string
|
||||
* description: 验证码唯一ID
|
||||
* image:
|
||||
* type: string
|
||||
* description: Base64编码的SVG验证码图片
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
|
||||
router.get('/generate', (req, res) => {
|
||||
try {
|
||||
// 生成验证码文本
|
||||
@@ -169,58 +136,7 @@ router.get('/generate', (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* @swagger
|
||||
* /captcha/verify:
|
||||
* post:
|
||||
* summary: 验证用户输入的验证码
|
||||
* tags: [Captcha]
|
||||
* requestBody:
|
||||
* required: true
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* required:
|
||||
* - captchaId
|
||||
* - captchaText
|
||||
* properties:
|
||||
* captchaId:
|
||||
* type: string
|
||||
* description: 验证码唯一ID
|
||||
* captchaText:
|
||||
* type: string
|
||||
* description: 用户输入的验证码
|
||||
* responses:
|
||||
* 200:
|
||||
* description: 验证码验证成功
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* example: true
|
||||
* message:
|
||||
* type: string
|
||||
* example: 验证码验证成功
|
||||
* 400:
|
||||
* description: 验证码错误或已过期
|
||||
* content:
|
||||
* application/json:
|
||||
* schema:
|
||||
* type: object
|
||||
* properties:
|
||||
* success:
|
||||
* type: boolean
|
||||
* example: false
|
||||
* message:
|
||||
* type: string
|
||||
* example: 验证码错误
|
||||
* 500:
|
||||
* description: 服务器错误
|
||||
*/
|
||||
|
||||
router.post('/verify', (req, res) => {
|
||||
try {
|
||||
const { captchaId, captchaText } = req.body;
|
||||
|
||||
Reference in New Issue
Block a user