Authored by 陈轩

找回密码 短信发送 增加 一段时间内 发送次数限制

@@ -199,19 +199,6 @@ const sendCodeToMobileAPI = (req, res, next) => { @@ -199,19 +199,6 @@ const sendCodeToMobileAPI = (req, res, next) => {
199 let areaCode = req.body.areaCode || '86'; 199 let areaCode = req.body.areaCode || '86';
200 let testCode = req.body.yohobuy; 200 let testCode = req.body.yohobuy;
201 201
202 - /* 如果设置了冻结时间,验证 */  
203 - if (_.has(req.session, 'backupCaptch.timeout')) {  
204 - let untilTime = (parseInt(req.session.backupCaptch.timeout, 10) -  
205 - parseInt(Date.now(), 10)) / 1000 / 60;  
206 -  
207 - if (parseInt(Date.now(), 10) < parseInt(req.session.backupCaptch.timeout, 10)) {  
208 - return res.json({  
209 - code: 401,  
210 - message: '请' + (parseInt(untilTime, 10) + 1) + '分钟后尝试!'  
211 - });  
212 - }  
213 - }  
214 -  
215 let errorCount = _.get(req.session, 'captchaValidCount', 4); // 初始1次 + 后续4次, 同一个验证码 共5次 202 let errorCount = _.get(req.session, 'captchaValidCount', 4); // 初始1次 + 后续4次, 同一个验证码 共5次
216 203
217 if (!errorCount) { 204 if (!errorCount) {
@@ -250,6 +237,7 @@ const sendCodeToMobileAPI = (req, res, next) => { @@ -250,6 +237,7 @@ const sendCodeToMobileAPI = (req, res, next) => {
250 }); 237 });
251 } 238 }
252 239
  240 +
253 let ERR = { 241 let ERR = {
254 code: 400, 242 code: 400,
255 message: '输入手机号码出错' 243 message: '输入手机号码出错'
@@ -259,7 +247,23 @@ const sendCodeToMobileAPI = (req, res, next) => { @@ -259,7 +247,23 @@ const sendCodeToMobileAPI = (req, res, next) => {
259 return res.json(ERR); 247 return res.json(ERR);
260 } 248 }
261 249
262 - 250 + let backCount = _.get(req.session, 'backupCaptch.count'); // 短信验证码 发送次数
  251 +
  252 + if (!backCount) {
  253 + /* 如果设置了冻结时间,验证 */
  254 + let untilTime = (parseInt(req.session.backupCaptch.timeout, 10) -
  255 + parseInt(Date.now(), 10)) / 1000 / 60;
  256 +
  257 + if (parseInt(Date.now(), 10) < parseInt(req.session.backupCaptch.timeout, 10)) {
  258 + return res.json({
  259 + code: 401,
  260 + message: '请' + (parseInt(untilTime, 10) + 1) + '分钟后尝试!'
  261 + });
  262 + } else {
  263 + _.set(req.session, 'backupCaptch.count', 5);
  264 + }
  265 + }
  266 +
263 267
264 service.sendCodeToMobileAsync(phoneNum, areaCode) 268 service.sendCodeToMobileAsync(phoneNum, areaCode)
265 .then(result => { 269 .then(result => {
@@ -269,6 +273,12 @@ const sendCodeToMobileAPI = (req, res, next) => { @@ -269,6 +273,12 @@ const sendCodeToMobileAPI = (req, res, next) => {
269 } 273 }
270 274
271 if (result.code === 200) { 275 if (result.code === 200) {
  276 + --req.session.backupCaptch.count;
  277 +
  278 + if (!req.session.backupCaptch.count) {
  279 + _.set(req.session, 'backupCaptch.timeout', Date.now() + 5 * 60 * 1000);
  280 + }
  281 +
272 return res.json({ 282 return res.json({
273 code: 200, 283 code: 200,
274 data: helpers.urlFormat('/passport/back/mobilecode', { 284 data: helpers.urlFormat('/passport/back/mobilecode', {