...
|
...
|
@@ -38,8 +38,8 @@ exports.beforeIn = (req, res, next) => { |
|
|
const _step1 = (req, res, next) => {
|
|
|
_.set(req.session, 'smsLogin.step', 1);
|
|
|
|
|
|
if (req.session.smsLogin.count == null) { // eslint-disable-line
|
|
|
req.session.smsLogin.count = 5;
|
|
|
if (req.session.captchaValidCount == null) { // eslint-disable-line
|
|
|
req.session.captchaValidCount = 5;
|
|
|
}
|
|
|
|
|
|
let template = 'sms/login';
|
...
|
...
|
@@ -135,6 +135,15 @@ exports.indexCheck = (req, res, next) => { |
|
|
|
|
|
let em = new EventEmitter();
|
|
|
|
|
|
|
|
|
let errorCount = _.get(req.session, 'captchaValidCount', 4 - 1); // 初始1次 + 后续4次, 同一个验证码 共5次
|
|
|
|
|
|
if (!errorCount) {
|
|
|
_.set(req.session, 'captchaValidCount', 3);
|
|
|
} else {
|
|
|
--req.session.captchaValidCount;
|
|
|
}
|
|
|
|
|
|
// 校验 成功
|
|
|
em.on('resolve', () => {
|
|
|
// 1. 将信息放入 session
|
...
|
...
|
@@ -144,14 +153,6 @@ exports.indexCheck = (req, res, next) => { |
|
|
|
|
|
PhoneService.sendSMS(mobile, area, 1);
|
|
|
|
|
|
--req.session.smsLogin.count;
|
|
|
|
|
|
if (!req.session.smsLogin.count) {
|
|
|
_.set(req.session, 'smsLogin.interval', Date.now() + 5 * 60 * 1000);
|
|
|
} else {
|
|
|
_.set(req.session, 'smsLogin.interval', Date.now() + 60 * 1000);
|
|
|
}
|
|
|
|
|
|
res.json({
|
|
|
code: 200,
|
|
|
redirect: '/passport/sms_login?step=2'
|
...
|
...
|
@@ -160,14 +161,18 @@ exports.indexCheck = (req, res, next) => { |
|
|
|
|
|
// 校验 失败
|
|
|
em.on('reject', error => {
|
|
|
if (req.session.captchaValidCount === 0) {
|
|
|
req.session.captcha = void 0; // 验证码 用过就扔
|
|
|
error.changeCaptcha = true;
|
|
|
}
|
|
|
|
|
|
_.set(req.session, 'smsLogin.step', 1);
|
|
|
|
|
|
|
|
|
res.json(error);
|
|
|
});
|
|
|
|
|
|
|
|
|
req.session.captcha = void 0; // 验证码 用过就扔
|
|
|
|
|
|
// 验证
|
|
|
if ([area, mobile].some(val => val === '')) {
|
|
|
return em.emit('reject', {code: 400, message: '请填写手机号'});
|
...
|
...
|
|