captcha.js 986 Bytes
/**
 * Created by TaoHuang on 2016/6/18.
 */

'use strict';

const _ = require('lodash');
const library = '../../../library';
const captcha = require('../models/captcha-service');
const helpers = require(library + '/helpers');

exports.validateAPI = (req, res, next) => {
    let captchaToken = req.body.verifyCode || '';

    captcha.findByContentAsync(captchaToken)
        .then(result => {
            if (_.isEmpty(result)) {
                res.json({
                    code: 400,
                    message: '您输入的验证码不正确!'
                });
            } else {
                next();
            }
        });
};

exports.validatePage = (req, res, next) => {
    let captchaToken = req.body.verifyCode || '';

    captcha.findByContentAsync(captchaToken)
        .then(result => {
            if (_.isEmpty(result)) {
                res.redirect('/passport/back/index.html');
            } else {
                next();
            }
        });
};