captcha.js 1.06 KB
/**
 * 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
};