captcha.js 571 Bytes
'use strict';

let imgCheckAPI = require('../../serverAPI/imgcheck');

exports.get = (req, res, next) => {
    let data = {
        src: ''
    };

    return imgCheckAPI.gen().then(result => {
        if (result.code === 200) {
            let codeStr = result.data.degrees.reduce((str, rotate) => { 
                return str.concat((4 - rotate / 90 % 4) % 4);
            }, '');

            req.session.captcha = codeStr;

            data.src = result.data.verifiedGraphicCode;

            return res.json(data);
        }

        next();
    }).catch(next);
};