...
|
...
|
@@ -6,7 +6,6 @@ |
|
|
'use strict';
|
|
|
const _ = require('lodash');
|
|
|
const moment = require('moment');
|
|
|
const EventEmitter = require('events');
|
|
|
const SmsModel = require('../models/sms');
|
|
|
|
|
|
const smsController = {
|
...
|
...
|
@@ -48,13 +47,18 @@ const smsController = { |
|
|
* @param res
|
|
|
* @returns {*|boolean}
|
|
|
*/
|
|
|
sendCode(req, res) {
|
|
|
const em = new EventEmitter();
|
|
|
sendCode(req, res, next) {
|
|
|
const area = (req.body.area || '86').trim();
|
|
|
const mobile = (req.body.mobile || '').trim();
|
|
|
const inValid = [area, mobile].some(v => v === '');
|
|
|
|
|
|
em.on('resolve', () => {
|
|
|
if (inValid) {
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: '请填写手机号'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
req.ctx(SmsModel).sendSMS(mobile, area, 1)
|
|
|
.then(result => {
|
|
|
if (result.code === 200) {
|
...
|
...
|
@@ -80,23 +84,8 @@ const smsController = { |
|
|
code: 500,
|
|
|
message: '验证码发送失败'
|
|
|
});
|
|
|
});
|
|
|
});
|
|
|
|
|
|
em.on('reject', error => {
|
|
|
res.json(error);
|
|
|
});
|
|
|
|
|
|
|
|
|
if (!inValid) {
|
|
|
em.emit('resolve');
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
em.emit('reject', {
|
|
|
code: 400,
|
|
|
message: '请填写手机号'
|
|
|
});
|
|
|
})
|
|
|
.catch(next);
|
|
|
},
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -106,8 +95,8 @@ const smsController = { |
|
|
*/
|
|
|
checkCode(req, res, next) {
|
|
|
const code = (req.body.code || '').trim();
|
|
|
const mobile = (req.body.mobile || '').trim();
|
|
|
const area = _.get(req.session, 'smsSend.area', '');
|
|
|
const mobile = _.get(req.session, 'smsSend.mobile', '');
|
|
|
|
|
|
req.ctx(SmsModel).verifySMS(mobile, area, code, 1)
|
|
|
.then(result => {
|
...
|
...
|
|