captcha.js
587 Bytes
'use strict';
let imgCheckAPI = require('../models/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.replace(/^http:/, '');
return res.json(data);
}
next();
}).catch(next);
};