captcha.js 1.15 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) => {
    return (_.get(req.app.locals.pc, 'geetest.validation', false) ?
        gee.requiredAPI :
        img.requiredAPI)(req, res, 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);
};

const passwordRequired = (req, res, next) => {
    if (req.body.loginType === 'password') {
        return requiredAPI(req, res, next);
    } else {
        return next();
    }
};

module.exports = {
    requiredAPI,
    requiredPage,
    generate,
    checkAPI,
    passwordRequired
};