...
|
...
|
@@ -10,6 +10,7 @@ const _ = require('lodash'); |
|
|
const helpers = global.yoho.helpers;
|
|
|
|
|
|
const service = require('../models/back-service');
|
|
|
const captchaService = require('../models/captcha-service');
|
|
|
|
|
|
const SIGN_IN = helpers.urlFormat('/passport/login');
|
|
|
|
...
|
...
|
@@ -150,18 +151,86 @@ const indexMobilePage = (req, res, next) => { |
|
|
isPassportPage: true,
|
|
|
backMobile: true,
|
|
|
countrys: result.data,
|
|
|
areaCode: '+86'
|
|
|
areaCode: '+86',
|
|
|
verifySrc: helpers.urlFormat('/passport/back/generatecodeimg.png', {t: Date.now()})
|
|
|
}));
|
|
|
})
|
|
|
.catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 生成验证码
|
|
|
* @param req
|
|
|
* @param res
|
|
|
*/
|
|
|
const generateCodeImg = (req, res) => {
|
|
|
let verifyCodeImg = captchaService.generateCaptcha(109, 50, 4);
|
|
|
|
|
|
if (verifyCodeImg) {
|
|
|
|
|
|
if (req.session.backupCaptch) {
|
|
|
req.session.backupCaptch.code = verifyCodeImg.text;
|
|
|
} else {
|
|
|
req.session.backupCaptch = {
|
|
|
code: verifyCodeImg.text,
|
|
|
};
|
|
|
}
|
|
|
|
|
|
res.set('Cache-Control', 'no-cache').send(verifyCodeImg.image);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 发送手机验证码
|
|
|
*/
|
|
|
const sendCodeToMobileAPI = (req, res, next) => {
|
|
|
let verifyCode = req.body.verifyCode || '';
|
|
|
let phoneNum = req.body.phoneNum || '';
|
|
|
let areaCode = req.body.areaCode || '86';
|
|
|
|
|
|
/* 如果设置了冻结时间,验证 */
|
|
|
if (_.has(req.session, 'backupCaptch.timeout')) {
|
|
|
let untilTime = (parseInt(req.session.backupCaptch.timeout, 10) -
|
|
|
parseInt(Date.now(), 10)) / 1000 / 60;
|
|
|
|
|
|
if (parseInt(Date.now(), 10) < parseInt(req.session.backupCaptch.timeout, 10)) {
|
|
|
return res.json({
|
|
|
code: 401,
|
|
|
message: '请' + (parseInt(untilTime, 10) + 1) + '分钟后尝试!'
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* 如果有设置验证次数,验证是否合法,验证次数减 1;没有,设置验证次数 */
|
|
|
if (_.has(req.session, 'backupCaptch.useTime')) {
|
|
|
if (parseInt(req.session.backupCaptch.useTime, 10) <= 0) {
|
|
|
|
|
|
/* 如果超过验证次数,冻结 5 分钟,更新验证次数 */
|
|
|
req.session.backupCaptch.timeout = Date.now() + 5 * 60 * 1000;
|
|
|
req.session.backupCaptch.useTime = 5;
|
|
|
return res.json({
|
|
|
code: 401,
|
|
|
message: '请5分钟后尝试!'
|
|
|
});
|
|
|
}
|
|
|
req.session.backupCaptch.useTime = req.session.backupCaptch.useTime - 1;
|
|
|
} else {
|
|
|
req.session.backupCaptch.useTime = 5;
|
|
|
}
|
|
|
|
|
|
/* 只校验一次,校验验证码 */
|
|
|
if (_.get(req.session, 'backupCaptch.useTime', 0) === 5 &&
|
|
|
!verifyCode || verifyCode.toString() !== _.get(req, 'session.backupCaptch.code', '').toString()) {
|
|
|
req.session.backupCaptch.code = null;
|
|
|
|
|
|
return res.json({
|
|
|
code: 400,
|
|
|
message: '验证码输入错误'
|
|
|
});
|
|
|
} else {
|
|
|
req.session.backupCaptch.code = null;
|
|
|
}
|
|
|
|
|
|
let ERR = {
|
|
|
code: 400,
|
|
|
message: '输入手机号码出错'
|
...
|
...
|
@@ -183,7 +252,8 @@ const sendCodeToMobileAPI = (req, res, next) => { |
|
|
code: 200,
|
|
|
data: helpers.urlFormat('/passport/back/mobilecode', {
|
|
|
phoneNum: phoneNum,
|
|
|
areaCode: areaCode
|
|
|
areaCode: areaCode,
|
|
|
verifyCode: verifyCode
|
|
|
})
|
|
|
});
|
|
|
}
|
...
|
...
|
@@ -208,8 +278,8 @@ const verifyCodeByMobilePage = (req, res) => { |
|
|
isPassportPage: true,
|
|
|
backCode: true,
|
|
|
areaCode: areaCode,
|
|
|
phoneNum: phoneNum
|
|
|
|
|
|
phoneNum: phoneNum,
|
|
|
verifySrc: helpers.urlFormat('/passport/back/generatecodeimg.png', {t: Date.now()})
|
|
|
}));
|
|
|
};
|
|
|
|
...
|
...
|
@@ -309,5 +379,6 @@ module.exports = { |
|
|
verifyCodeByMobilePage,
|
|
|
verifyCodeByMobileAPI,
|
|
|
setNewPasswordByMobilePage,
|
|
|
setNewPasswordByMobileAPI
|
|
|
setNewPasswordByMobileAPI,
|
|
|
generateCodeImg
|
|
|
}; |
...
|
...
|
|