captcha.js
1.06 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
/**
* Created by TaoHuang on 2016/6/18.
*/
'use strict';
const _ = require('lodash');
const gee = require('./gee-captcha');
const img = require('./img-captcha');
const requiredAPI = (req, res, next) => {
let captchaAPI = _.get(req.app.locals.pc, 'geetest.validation', false) ? gee.requiredAPI : img.requiredAPI;
if (req.body.loginType === 'password') {
return captchaAPI(req, res, next);
} else {
return next();
}
};
const generate = (req, res) => {
return (_.get(req.app.locals.pc, 'geetest.validation', false) ?
gee.generate :
img.generate)(req, res);
};
// 端到端检查
const checkAPI = (req, res) => {
return (_.get(req.app.locals.pc, 'geetest.validation', false) ?
gee.checkAPI :
img.checkAPI)(req, res);
};
// 重定向调用
const requiredPage = (req, res, next) => {
return (_.get(req.app.locals.pc, 'geetest.validation', false) ?
gee.requiredPage :
img.requiredPage)(req, res, next);
};
module.exports = {
requiredAPI,
requiredPage,
generate,
checkAPI
};