Authored by 姜枫

add check page

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