captcha.js
1.17 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
'use strict';
const imgCheckServiceModel = require('../models/imgcheck');
const request = require('request');
exports.get = (req, res, next) => {
let data = {
src: ''
};
let udid = req.session.id;
return req.ctx(imgCheckServiceModel).gen(udid).then(result => {
if (result.code === 200 && result.data) {
data.src = `/passport/img-check.jpg?t=${Date.now()}`;
return res.json(data);
}
next();
}).catch(next);
};
exports.imgCheck = (req, res, next) => {
let udid = req.session.id;
return req.ctx(imgCheckServiceModel).gen(udid).then(result => {
if (result.code === 200 && result.data) {
return request(result.data.verifiedGraphicCode).pipe(res); // eslint-disable-line
}
next();
}).catch(next);
};
/**
* 验证img-check验证码
*/
exports.validate = (req, res, next) => {
let udid = req.session.id;
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);
}
});
};