...
|
...
|
@@ -7,23 +7,25 @@ const _ = require('lodash'); |
|
|
const gee = require('./gee-captcha');
|
|
|
const img = require('./img-captcha');
|
|
|
|
|
|
const isGeetest = (req) => {
|
|
|
if (_.get(req.app.locals.pc, 'geetest.validation', false)) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
return req.session.captchaType === 'geetest';
|
|
|
};
|
|
|
|
|
|
const requiredAPI = (req, res, next) => {
|
|
|
return (_.get(req.app.locals.pc, 'geetest.validation', false) ?
|
|
|
gee.requiredAPI :
|
|
|
img.requiredAPI)(req, res, next);
|
|
|
return (isGeetest(req) ? gee.requiredAPI : img.requiredAPI)(req, res, next);
|
|
|
};
|
|
|
|
|
|
const generate = (req, res) => {
|
|
|
return (_.get(req.app.locals.pc, 'geetest.validation', false) ?
|
|
|
gee.generate :
|
|
|
img.generate)(req, res);
|
|
|
return (isGeetest(req) ? gee.generate : img.generate)(req, res);
|
|
|
};
|
|
|
|
|
|
// 端到端检查
|
|
|
const checkAPI = (req, res) => {
|
|
|
return (_.get(req.app.locals.pc, 'geetest.validation', false) ?
|
|
|
gee.checkAPI :
|
|
|
img.checkAPI)(req, res);
|
|
|
return (isGeetest(req) ? gee.checkAPI : img.checkAPI)(req, res);
|
|
|
};
|
|
|
|
|
|
const passwordRequired = (req, res, next) => {
|
...
|
...
|
@@ -34,9 +36,17 @@ const passwordRequired = (req, res, next) => { |
|
|
}
|
|
|
};
|
|
|
|
|
|
const captchaSwitcher = (req, res, next) => {
|
|
|
if (isGeetest(req)) {
|
|
|
req.app.locals.geetest = true;
|
|
|
}
|
|
|
next();
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
requiredAPI,
|
|
|
generate,
|
|
|
checkAPI,
|
|
|
passwordRequired
|
|
|
passwordRequired,
|
|
|
captchaSwitcher
|
|
|
}; |
...
|
...
|
|