robot-check.js
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
'use strict';
const robotCheckService = require('../models/robot-check-service');
const captchaService = require('../../passport/controllers/captcha');
const headerModel = require('../../../doraemon/models/header');
const logger = global.yoho.logger;
const index = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
req.ctx(headerModel).requestHeaderData(channel).then((result) => {
return res.render('robot-check', Object.assign({
module: '3party',
page: 'robot-check'
}, result));
}).catch(next);
};
const check = captchaService.geeCheck;
const img = captchaService.geeGenerate;
const isHuman = (req, res) => {
let remoteIp = req.yoho.clientIp;
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
remoteIp = arr[0];
}
const apiLimitValidate = req.session.apiLimitValidate;
delete req.session.apiLimitValidate;
logger.warn('isHuman', remoteIp);
return robotCheckService.removeBlack(remoteIp, apiLimitValidate, req.headers.referer).then(() => {
return res.json({
code: 200
});
}).catch(() => {
return res.json({
code: 400
});
});
};
module.exports = {
index,
check,
isHuman,
img
};