Authored by 郭成尧

not-imgcheck-geetest

@@ -9,7 +9,6 @@ const _ = require('lodash'); @@ -9,7 +9,6 @@ const _ = require('lodash');
9 const config = global.yoho.config; 9 const config = global.yoho.config;
10 const co = Promise.coroutine; 10 const co = Promise.coroutine;
11 const geetest = require('./geetest'); 11 const geetest = require('./geetest');
12 -const captcha = require('./captcha');  
13 const imgCheck = require('../models/imgcheck'); 12 const imgCheck = require('../models/imgcheck');
14 13
15 /** 14 /**
@@ -17,17 +16,16 @@ const imgCheck = require('../models/imgcheck'); @@ -17,17 +16,16 @@ const imgCheck = require('../models/imgcheck');
17 */ 16 */
18 const load = (req, res, next) => { 17 const load = (req, res, next) => {
19 co(function* () { 18 co(function* () {
20 - res.locals.useGeetest = false;  
21 -  
22 let isNeedImgCheckApiData = yield req.ctx(imgCheck).isNeedImgCheck(req.sessionID); 19 let isNeedImgCheckApiData = yield req.ctx(imgCheck).isNeedImgCheck(req.sessionID);
23 20
24 if (_.parseInt(_.get(isNeedImgCheckApiData, 'code')) === 200) { 21 if (_.parseInt(_.get(isNeedImgCheckApiData, 'code')) === 200) {
25 req.yoho.captchaShow = _.get(isNeedImgCheckApiData, 'data'); 22 req.yoho.captchaShow = _.get(isNeedImgCheckApiData, 'data');
26 } else { 23 } else {
27 req.yoho.captchaShow = false; 24 req.yoho.captchaShow = false;
28 - res.locals.useGeetest = true;  
29 } 25 }
30 26
  27 + res.locals.useGeetest = !req.yoho.captchaShow;
  28 +
31 if (_.has(res, 'locals.loadJs')) { 29 if (_.has(res, 'locals.loadJs')) {
32 res.locals.loadJs.push({ 30 res.locals.loadJs.push({
33 src: global.yoho.config.geetestJs 31 src: global.yoho.config.geetestJs
@@ -54,8 +52,6 @@ const check = (req, res, next) => { @@ -54,8 +52,6 @@ const check = (req, res, next) => {
54 } 52 }
55 53
56 co(function* () { 54 co(function* () {
57 - res.locals.useGeetest = false;  
58 -  
59 let isNeedImgCheckApiData = yield req.ctx(imgCheck).isNeedImgCheck(req.sessionID); 55 let isNeedImgCheckApiData = yield req.ctx(imgCheck).isNeedImgCheck(req.sessionID);
60 56
61 req.yoho.captchaShow = true; 57 req.yoho.captchaShow = true;
@@ -63,11 +59,11 @@ const check = (req, res, next) => { @@ -63,11 +59,11 @@ const check = (req, res, next) => {
63 req.yoho.captchaShow = _.get(isNeedImgCheckApiData, 'data'); 59 req.yoho.captchaShow = _.get(isNeedImgCheckApiData, 'data');
64 } else { 60 } else {
65 req.yoho.captchaShow = false; 61 req.yoho.captchaShow = false;
66 - res.locals.useGeetest = true;  
67 } 62 }
  63 + res.locals.useGeetest = !req.yoho.captchaShow;
68 return res.locals.useGeetest; 64 return res.locals.useGeetest;
69 })().then(function() { 65 })().then(function() {
70 - return (res.locals.useGeetest ? geetest : captcha).validate(req, res, next); 66 + return res.locals.useGeetest ? geetest.validate(req, res, next) : next();
71 }); 67 });
72 }; 68 };
73 69