Authored by 周少峰

Merge branch 'feature/geetest' into hotfix/salePage

... ... @@ -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();
});
... ...
... ... @@ -10,6 +10,7 @@ const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
const auth = require(`${global.middleware}/auth`);
const captcha = require('../passport/controllers/captcha');
const ads = require(`${cRoot}/ads`); // 第三方广告平台对接
const robot = require(`${cRoot}/robot-check`); // 机器人检查
... ... @@ -17,7 +18,7 @@ const materialController = require(`${cRoot}/material`);
const activate = require(`${cRoot}/activate`); // 激活点击统计
router.get('/ads', ads.jump);
router.get('/check', robot.index);
router.get('/check', captcha.tryGeetest, robot.index);
router.post('/check', robot.check, robot.isHuman);
router.get('/material', auth, materialController.index);
... ...
... ... @@ -8,6 +8,7 @@
const express = require('express');
const router = express.Router(); // eslint-disable-line
const cRoot = './controllers';
const captcha = require('../passport/controllers/captcha');
const newUserController = require(`${cRoot}/new-user`);
... ... @@ -196,11 +197,11 @@ router.post('/cancelbind/:type', bindController.cancelBind);
// 账号安全
router.get('/account', tabsMiddleware.getCommonHeader, AccountController.index);
router.get('/account/userpwd', tabsMiddleware.getCommonHeader, AccountController.userPwd);
router.get('/account/userpwd', tabsMiddleware.getCommonHeader, captcha.tryGeetest, AccountController.userPwd);
router.get('/account/email', tabsMiddleware.getCommonHeader, AccountController.userEmail);
router.get('/account/email', tabsMiddleware.getCommonHeader, captcha.tryGeetest, AccountController.userEmail);
router.get('/account/mobile', tabsMiddleware.getCommonHeader, AccountController.userMobile);
router.get('/account/mobile', tabsMiddleware.getCommonHeader, captcha.tryGeetest, AccountController.userMobile);
router.post('/account/checkverifycode', tabsMiddleware.getCommonHeader, AccountController.checkVerifyCode);
... ... @@ -244,7 +245,7 @@ router.get('/address/defaultAddress', AddressController.defaultAddress);
// 兑换礼品卡
router.get('/gift', tabsMiddleware.getCommonHeader, giftController.index);
router.get('/gift', tabsMiddleware.getCommonHeader, captcha.tryGeetest, giftController.index);
router.post('/gift/exchange', giftController.exchange);
... ...
... ... @@ -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 req.session.captchaType !== 'img';
}
return false;
};
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,20 @@ const passwordRequired = (req, res, next) => {
}
};
const tryGeetest = (req, res, next) => {
if (isGeetest(req)) {
req.app.locals.geetest = true;
} else {
req.app.locals.geetest = false;
}
next();
};
module.exports = {
requiredAPI,
generate,
checkAPI,
passwordRequired
passwordRequired,
tryGeetest
};
... ...
... ... @@ -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,17 +22,25 @@ 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);
req.session.captchaType = 'img';
res.json({
code: 501,
data: data
});
} else {
// 正常模式
res.send(data);
req.session.captchaType = 'geetest';
res.send({
code: 200,
data: data
});
}
});
};
... ...
... ... @@ -3,10 +3,8 @@
*/
'use strict';
const _ = require('lodash');
const captchaService = require('../models/captcha-img-service');
const helpers = global.yoho.helpers;
const CAPTCHA = global.yoho.config.UNIVERSAL_CAPTCHA;
const request = require('request');
const logger = global.yoho.logger;
... ...
... ... @@ -20,7 +20,7 @@ const auth = require(`${global.middleware}/auth`);
const router = express.Router(); // eslint-disable-line
// 兼容老的路由
router.get('/signin.html', login.common.beforeLogin, login.local.loginPage);
router.get('/signin.html', login.common.beforeLogin, captcha.tryGeetest, login.local.loginPage);
router.get('/reg.html', reg.index);
router.get('/logout.html', login.local.logout);
... ... @@ -34,7 +34,7 @@ router.post('/passport/login/sms/checkuser', login.local.sms.checkUser); // 短
router.post('/passport/login/qrcode/refresh', login.local.qrcode.refresh); // 刷新二维码
router.post('/passport/login/qrcode/check', login.local.qrcode.check); // 验证二维码的状态
router.get('/passport/login', login.common.beforeLogin, login.local.loginPage);
router.get('/passport/login', login.common.beforeLogin, captcha.tryGeetest, login.local.loginPage);
router.post('/passport/login/auth', captcha.passwordRequired, login.local.login);
router.get('/passport/logout', login.local.logout);
... ... @@ -94,7 +94,7 @@ router.post('/passport/cert/relateMobile', auth, cert.relateMobile);
/**
* 注册页面路由
*/
router.get('/passport/reg/index', reg.index);
router.get('/passport/reg/index', captcha.tryGeetest, reg.index);
// NOTE: 该接口的存在只是为了兼容前端 ajax 请求
router.post('/passport/reg/checkmobile', reg.fakeCheckMobile);
... ... @@ -117,7 +117,7 @@ router.get('/passport/reg/success', reg.success);
* 找回密码首页信息
*/
// 找回密码首页
router.get('/passport/back/index', back.index);
router.get('/passport/back/index', captcha.tryGeetest, back.index);
// 验证输入是否正确
router.post('/passport/back/authcode',
... ...
... ... @@ -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/',
... ...
{{#if @root.pc.geetest.validation}}
{{#if @root.geetest}}
<script>window._geeCaptcha = true;</script>
<script src="http://static.geetest.com/static/tools/gt.js"></script>
{{/if}}
... ...
... ... @@ -32,12 +32,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) {
window.location.reload(true);
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));
});
... ... @@ -80,7 +85,7 @@ GeeCaptcha.prototype = {
var _this = this;
return $.sleep(500).then(function() {
_this._captchObj.refresh();
_this._captchObj && _this._captchObj.refresh();
});
},
... ...