robot-check.js 1.17 KB
'use strict';

const robotCheckService = require('../models/robot-check-service');
const captchaService = require('../../passport/controllers/captcha');
const logger = global.yoho.logger;
const index = (req, res, next) => {
    let channel = req.yoho.channel || 'boys';

    robotCheckService.index(channel).then((result) => {
        return res.render('robot-check', Object.assign({
            module: '3party',
            page: 'robot-check'
        }, result));
    }).catch(next);
};

const check = captchaService.geeCheck;

const img = captchaService.geeGenerate;

const isHuman = (req, res) => {
    let remoteIp = req.yoho.clientIp;

    if (remoteIp.indexOf(',') > 0) {
        let arr = remoteIp.split(',');

        remoteIp = arr[0];
    }
    const apiLimitValidate = req.session.apiLimitValidate;

    delete req.session.apiLimitValidate;

    logger.warn('isHuman', remoteIp);
    return robotCheckService.removeBlack(remoteIp, apiLimitValidate).then(() => {
        return res.json({
            code: 200
        });
    }).catch(() => {
        return res.json({
            code: 400
        });
    });
};

module.exports = {
    index,
    check,
    isHuman,
    img
};