Authored by ccbikai(👎🏻🍜)

增加极验证

'use strict';
const _ = require('lodash');
const Geetest = require('geetest');
const captcha = new Geetest({
... ... @@ -21,6 +23,14 @@ const geetest = {
}).catch(next);
},
validate(req, res, next) {
// 使用极验证
let useGeetest = _.get(req.app.locals.wap, 'geetest.validation', true);
if (!useGeetest) {
return next();
}
captcha.validate({
challenge: 'xxx',
validate: 'xxx',
... ... @@ -29,9 +39,10 @@ const geetest = {
if (success) {
return next();
}
return res.send(403, {
code: 403,
message: 'captcha error'
return res.send({
code: 400,
message: '验证码错误',
captchaShow: true
});
});
}
... ...
... ... @@ -111,6 +111,7 @@ const local = {
res.render('login', {
width750: true,
loginIndex: true, // 模板中使用JS的标识
useGeetest: _.get(req.app.locals.wap, 'geetest.validation', true), // 使用极验证
// captchaShow: _.get(req.session, 'login.errorCount') <= 0,
captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码
... ... @@ -169,6 +170,7 @@ const local = {
// 返回的URL链接
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
loginInternational: true, // 模板中使用JS的标识
useGeetest: _.get(req.app.locals.wap, 'geetest.validation', true), // 使用极验证
// captchaShow: _.get(req.session, 'login.errorCount') <= 0,
captchaShow: true, // 170306 因为暴力破解密码问题,要求每次都展示验证码
... ... @@ -192,7 +194,11 @@ const local = {
_.set(req.session, 'login.errorCount', 3);
}
if (count <= 0) {
// 使用极验证
let useGeetest = _.get(req.app.locals.wap, 'geetest.validation', true);
// 有货自有验证码
if (count <= 0 && !useGeetest) {
let captchaInput = req.body.captcha;
let captchaCode = _.get(req.session, 'captcha');
let testCode = req.body.yohobuy;
... ...
... ... @@ -44,7 +44,7 @@ router.get('/passport/login', login.common.beforeLogin, login.local.loginPage);
router.get('/passport/international', login.common.beforeLogin, login.local.international);
// 本地登录
router.post('/passport/login/auth', login.local.login);
router.post('/passport/login/auth', geetest.validate, login.local.login);
// SMS 短信
router.use('/passport/sms_login', login.common.beforeLogin, smsLogin.beforeIn);
... ...
... ... @@ -9,8 +9,8 @@
<div class="input-container row has-eye">
<input id="pwd" class="pwd input" type="password" placeholder="密码">
</div>
<div id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div>
<div data-geetest="{{useGeetest}}" id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div>
<span id="btn-login" class="btn btn-login disble row">登录</span>
</div>
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -8,7 +8,7 @@
<div class="input-container row has-eye">
<input id="pwd" class="pwd input" type="password" placeholder="密码">
</div>
<div id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div>
<div data-geetest="{{useGeetest}}" id="js-img-check" {{#captchaShow }}data-init{{/captchaShow}}></div>
<span id="btn-login" class="btn btn-login disable">登录</span>
<p class="op-container">
<a class="op-item internat" href={{internationalUrl}}>海外手机</a>
... ... @@ -23,12 +23,12 @@
<a class="alipay" href={{aliLoginUrl}}></a>
</div>
</div>
<div class="login-tip">
<div class="info-icon"></div>
Yoho!Family账号可登录Yoho!Buy有货
</div>
<div id="retrive-pwd-mask" class="mask"></div>
<ul id="retrive-pwd-ways" class="retrive-pwd-ways">
<li>
... ...