captcha.js
2.07 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
'use strict';
const imgCheckServiceModel = require('../models/imgcheck');
const request = require('request');
exports.get = (req, res, next) => {
let data = {
src: ''
};
let udid = req.cookies.udid;
return req.ctx(imgCheckServiceModel).gen(udid).then(result => {
if (result.code === 200 && result.data) {
data.src = `/passport/img-check?t=${Date.now()}`;
return res.json(data);
}
next();
}).catch(next);
};
exports.imgCheck = (req, res, next) => {
let udid = req.cookies.udid;
return req.ctx(imgCheckServiceModel).gen(udid).then(result => {
if (result.code === 200 && result.data) {
return request({
url: result.data.verifiedGraphicCode,
headers: {
'X-request-ID': req.reqID || '',
'X-YOHO-IP': req.yoho.clientIp || '',
'X-Forwarded-For': req.yoho.clientIp || '',
'User-Agent': 'yoho/nodejs'
}
}).pipe(res); // eslint-disable-line
}
next();
}).catch(next);
};
exports.imgCheckRisk = (req, res, next) => {
if (!req.session.apiRiskValidate) {
return next();
}
return req.ctx(imgCheckServiceModel).getRiskCheckImg(req.cookies.udid).then(result => {
return request({
url: result,
headers: {
'X-request-ID': req.reqID || '',
'X-YOHO-IP': req.yoho.clientIp || '',
'X-Forwarded-For': req.yoho.clientIp || '',
'User-Agent': 'yoho/nodejs'
}
}).pipe(res); // eslint-disable-line
}).catch(next);
};
/**
* 验证img-check验证码
*/
exports.validate = (req, res, next) => {
// let udid = req.cookies.udid;
// let captchaInput = req.body.captcha;
// return req.ctx(imgCheckServiceModel).check(udid, captchaInput).then(result => {
// if (result.code === 200) {
// return next();
// } else {
// return res.json(result);
// }
// });
return next();
};