Authored by htoooth

fix

... ... @@ -149,13 +149,13 @@ app.use((req, res, next) => {
req.session = {};
}
//req.app.locals = _.merge(req.app.locals, {
// pc: {
// geetest: {
// validation: true
// }
// }
//});
req.app.locals = _.merge(req.app.locals, {
pc: {
geetest: {
validation: true
}
}
});
next();
});
... ...
... ... @@ -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
};
... ...
... ... @@ -9,7 +9,6 @@ const Geetest = require('../models/captcha-gee-service');
const config = global.yoho.config;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const CAPTCHA = config.UNIVERSAL_CAPTCHA;
... ... @@ -23,18 +22,30 @@ var pcGeetest = new Geetest({
geetest_key: config.gee_captcha.key
});
const generate = (req, res) => {
const generate = (req, res, next) => {
pcGeetest.register(function(err, data) {
if (err) {
return;
}
if (!data.success) {
res.send(data);
} else {
// 正常模式
res.send(data);
}
//if (!data.success) {
// res.json({
// code: 501,
// data: data
// });
//} else {
// // 正常模式
// req.session.captchaType = 'geetest';
// res.send({
// code: 200,
// data: data
// });
//}
res.json({
code: 501,
data: data
});
});
};
... ...
... ... @@ -51,6 +51,7 @@ const generate = (req, res, next) => {
captchaService.generateCaptcha().then((result) => {
req.session.captcha = result.data.text;
req.session.captchaCount = 0;
req.session.captchaType = 'img';
res.type('png');
if (result.code === 200) {
... ...
... ... @@ -17,15 +17,15 @@ module.exports = {
cookieDomain: '.yohobuy.com',
domains: {
// test3
// singleApi: 'http://api-test3.yohops.com:9999/',
// api: 'http://api-test3.yohops.com:9999/',
// service: 'http://service-test3.yohops.com:9999/',
singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.yohops.com:9999/',
service: 'http://service-test3.yohops.com:9999/',
// prod
singleApi: 'http://single.yoho.cn/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
//singleApi: 'http://single.yoho.cn/',
//api: 'http://api.yoho.cn/',
//service: 'http://service.yoho.cn/',
//
// gray
// singleApi: 'http://single.gray.yohops.com/',
// api: 'http://api.gray.yohops.com/',
... ...
... ... @@ -21,6 +21,7 @@ var GeeCaptcha = function(container, options) {
this._captchObj = null;
this.successCb = null;
this.refreshCb = null;
this.onFailCb = null;
// NODE: 这个是专门给自动化测试做的后门
this.$_____trojanYohobuy = this.$container.find('#yohobuy');
... ... @@ -32,12 +33,17 @@ GeeCaptcha.prototype = {
init: function() {
var _this = this;
$.get(_this.initURI + '?t=' + $.now()).then(function(data) {
$.get(_this.initURI + '?t=' + $.now()).then(function(result) {
if (result.code === 501) {
this.onFailCb && this.onFailCb();
return;
}
initGeetest && initGeetest({ // eslint-disable-line
gt: data.gt,
challenge: data.challenge,
gt: result.data.gt,
challenge: result.data.challenge,
product: 'float', // 产品形式,包括:float,embed,popup。注意只对PC版验证码有效
offline: !data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
offline: !result.data.success // 表示用户后台检测极验服务器是否宕机,一般不需要关注
}, $.proxy(_this.initCallback, _this));
});
... ... @@ -94,6 +100,11 @@ GeeCaptcha.prototype = {
return this;
},
onFail: function(cb) {
this.onFailCb = cb;
return this;
},
check: function() {
var _this = this;
... ...
... ... @@ -123,6 +123,11 @@ Captcha.prototype = {
return this;
},
onFail: function() {
// pass
return this;
},
/**
* 检查是否正确
*/
... ...