captcha.js
1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Created by TaoHuang on 2016/6/18.
*/
'use strict';
const _ = require('lodash');
const library = '../../../library';
const sessionService = require('../models/session-service');
const captcha = require('../models/captcha-service')(sessionService);
const helpers = require(library + '/helpers');
exports.checkAPI = (req, res, next) => {
let captchaToken = req.param('verifyCode', '');
captcha.findByContentAsync(captchaToken)
.then(result => {
if (_.isEmpty(result)) {
res.json({
code: 400,
message: '您输入的验证码不正确!'
});
} else {
next();
}
});
};
exports.checkPage = (req, res, next) => {
let captchaToken = req.param('verifyCode', '');
captcha.findByContentAsync(captchaToken)
.then(result => {
if (_.isEmpty(result)) {
res.redirect(helpers.urlFormat('/passport/back/index.html'));
} else {
next();
}
});
};