Authored by 郭成尧

verify-ip-once

... ... @@ -15,7 +15,7 @@ const cookie = global.yoho.cookie;
const helpers = global.yoho.helpers;
const log = global.yoho.logger;
const config = global.yoho.config;
const cache = global.yoho.cache.master;
const cache = global.yoho.cache;
const utils = require(global.utils);
const RegService = require('../models/reg-service');
const AuthHelper = require('../models/auth-helper');
... ... @@ -191,7 +191,7 @@ const local = {
captchaShow: true
};
cache.setAsync(`loginErrorIp:${req.yoho.clientIp}`, true, 3600).catch(log.error);
cache.set(`loginErrorIp:${req.yoho.clientIp}`, true, 3600).catch(log.error);
res.json(obj);
} else {
... ... @@ -399,12 +399,14 @@ exports.loginShowCaptchaByIp = function(req, res, next) {
// 开关打开,不走任何验证逻辑
if (!req.yoho.captchaShow) {
return next();
} else {
req.yoho.captchaShow = false;
}
co(function*() {
let hasErrorLog = yield cache.getAsync(`loginErrorIp:${req.yoho.clientIp}`);
let hasErrorLog = yield cache.get(`loginErrorIp:${req.yoho.clientIp}`);
log.info(`clientip ${req.yoho.clientIp} status is ` + cache.get(`loginErrorIp:${req.yoho.clientIp}`));
log.info(`clientip ${req.yoho.clientIp} status is ` + hasErrorLog);
if (hasErrorLog) {
req.yoho.captchaShow = true;
... ...
... ... @@ -8,7 +8,7 @@
const _ = require('lodash');
const config = global.yoho.config;
const co = Promise.coroutine;
const cache = global.yoho.cache.master;
const cache = global.yoho.cache;
const geetest = require('./geetest');
const captcha = require('./captcha');
... ... @@ -23,16 +23,21 @@ const check = (req, res, next) => {
}
// 默认取配置总开关来决定是否展示验证码
req.yoho.captchaShow = _.get(req.app.locals.wap, 'close.loginValidation', false);
req.yoho.captchaShow = !_.get(req.app.locals.wap, 'close.loginValidation', false);
co(function* () {
console.log('path:', req.path);
// 如果是账号密码登录,那么需要检查是否登录失败过,登录失败过展示验证码
if (req.path === '/passport/login/auth') {
let hasErrorLog = yield cache.getAsync(`loginErrorIp:${req.yoho.clientIp}`);
let hasErrorLog = yield cache.get(`loginErrorIp:${req.yoho.clientIp}`);
console.log('hasErrorLog:', req.yoho.captchaShow);
if (hasErrorLog) {
req.yoho.captchaShow = true;
} else {
req.yoho.captchaShow = false;
}
}
... ... @@ -47,6 +52,8 @@ const check = (req, res, next) => {
return next();
}
console.log('开始校验验证码');
// 使用极验证
let useGeetest = !_.get(req.app.locals.wap, 'geetest.validation', false);
... ...