Authored by 姜枫

add check page

'use strict';
const _ = require('lodash');
const cache = global.yoho.cache.master;
exports.index = (req, res) => {
res.render('check', {
... ... @@ -9,9 +11,29 @@ exports.index = (req, res) => {
exports.submit = (req, res) => {
let captchaCode = _.get(req.session, 'captcha');
let remoteIp = req.get('X-Forwarded-For') || req.ip;
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
remoteIp = arr[0];
}
if (req.body.captcha === captchaCode) {
return res.send('ok');
let key = `pc:limiter:${remoteIp}`;
cache.delAsync(key).then(() => {
return res.json({
code: 200
});
}).catch(() => {
return res.json({
code: 400
});
});
} else {
return res.json({
code: 400
});
}
return res.send('fail');
};
... ...
<div class="check-page">
<div class="title">请输入正确的验证码,继续访问</div>
<div id="js-img-check"></div>
<div class="submit">
确认
... ...
... ... @@ -72,7 +72,6 @@ module.exports = {
udp: { // send by udp
measurement: 'yohobuy_wap_node_log',
level: 'error', // logger level
host: 'influxdblog.web.yohoops.org', // influxdb host
port: '4444' // influxdb port
},
console: {
... ...
... ... @@ -14,9 +14,6 @@ module.exports = (req, res, next) => {
let limitAPI = helpers.urlFormat('/3party/check', {refer: refer});
let limitPage = helpers.urlFormat('/3party/check', {refer: req.protocol + '://' + req.get('host') + req.originalUrl});
limitAPI = limitAPI.replace('//m.yohobuy.com', 'http://www.yohobuy.com');
limitPage = limitPage.replace('//m.yohobuy.com', 'http://www.yohobuy.com');
if (_.indexOf(WHITE_LIST, req.path) >= 0) {
return next();
}
... ...
require('3party/check.page.css');
require('../common');
// 图片验证码
let ImgCheck = require('plugin/img-check');
... ... @@ -19,6 +19,13 @@ $(function() {
url: '/3party/check/submit',
data: {
captcha: $.trim(imgCheck.getResults())
},
success: function(ret) {
if (ret.code === 200) {
window.location.href = window.queryString.refer || '//m.yohobuy.com';
} else {
imgCheck.refresh();
}
}
});
});
... ...