Authored by 郭成尧

not-imgcheck-geetest

... ... @@ -9,7 +9,6 @@ const _ = require('lodash');
const config = global.yoho.config;
const co = Promise.coroutine;
const geetest = require('./geetest');
const captcha = require('./captcha');
const imgCheck = require('../models/imgcheck');
/**
... ... @@ -17,17 +16,16 @@ const imgCheck = require('../models/imgcheck');
*/
const load = (req, res, next) => {
co(function* () {
res.locals.useGeetest = false;
let isNeedImgCheckApiData = yield req.ctx(imgCheck).isNeedImgCheck(req.sessionID);
if (_.parseInt(_.get(isNeedImgCheckApiData, 'code')) === 200) {
req.yoho.captchaShow = _.get(isNeedImgCheckApiData, 'data');
} else {
req.yoho.captchaShow = false;
res.locals.useGeetest = true;
}
res.locals.useGeetest = !req.yoho.captchaShow;
if (_.has(res, 'locals.loadJs')) {
res.locals.loadJs.push({
src: global.yoho.config.geetestJs
... ... @@ -54,8 +52,6 @@ const check = (req, res, next) => {
}
co(function* () {
res.locals.useGeetest = false;
let isNeedImgCheckApiData = yield req.ctx(imgCheck).isNeedImgCheck(req.sessionID);
req.yoho.captchaShow = true;
... ... @@ -63,11 +59,11 @@ const check = (req, res, next) => {
req.yoho.captchaShow = _.get(isNeedImgCheckApiData, 'data');
} else {
req.yoho.captchaShow = false;
res.locals.useGeetest = true;
}
res.locals.useGeetest = !req.yoho.captchaShow;
return res.locals.useGeetest;
})().then(function() {
return (res.locals.useGeetest ? geetest : captcha).validate(req, res, next);
return res.locals.useGeetest ? geetest.validate(req, res, next) : next();
});
};
... ...