|
|
'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');
|
|
|
|
|
|
}; |
...
|
...
|
|