...
|
...
|
@@ -7,6 +7,8 @@ |
|
|
const captchaService = require('../models/captcha-service');
|
|
|
const helpers = global.yoho.helpers;
|
|
|
const CAPTCHA = 'yoho4946abcdef#$%&!@';
|
|
|
const request = require('request');
|
|
|
const uuid = require('uuid');
|
|
|
|
|
|
// 对比函数
|
|
|
const _mustEqual = (req) => {
|
...
|
...
|
@@ -79,6 +81,22 @@ const generate = (req, res, next) => { |
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
// 七牛验证码
|
|
|
const generateQiniu = (req, res, next) => {
|
|
|
captchaService.generateCaptcha().then((result) => {
|
|
|
req.session.captcha = result.data.text;
|
|
|
req.session.captchaCount = 0;
|
|
|
|
|
|
let imageUrl = result.data.images + `/watermark/2/text/${uuid.v4()}/fontsize/120/dissolve/10`;
|
|
|
|
|
|
res.type('png');
|
|
|
if (result.code === 200) {
|
|
|
request(imageUrl).pipe(res);
|
|
|
}
|
|
|
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
// 端到端检查
|
|
|
const checkAPI = (req, res) => {
|
|
|
let count = req.session.captchaCount;
|
...
|
...
|
@@ -110,5 +128,6 @@ module.exports = { |
|
|
requiredAPI,
|
|
|
requiredPage,
|
|
|
generate,
|
|
|
checkAPI
|
|
|
checkAPI,
|
|
|
generateQiniu
|
|
|
}; |
...
|
...
|
|