...
|
...
|
@@ -13,6 +13,9 @@ let helpers = global.yoho.helpers; |
|
|
let cache = global.yoho.cache;
|
|
|
let cookie = global.yoho.cookie;
|
|
|
|
|
|
/**
|
|
|
* 注册首页
|
|
|
*/
|
|
|
let index = (req, res, next) => {
|
|
|
// 设置注册有效时间30分钟, 防机器刷
|
|
|
req.session._REG_EXPIRE = Date.now() + 1800000;
|
...
|
...
|
@@ -41,6 +44,9 @@ let index = (req, res, next) => { |
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 检查手机号码是否注册过
|
|
|
*/
|
|
|
let checkMobile = (req, res, next) => {
|
|
|
let data = {
|
|
|
code: 400
|
...
|
...
|
@@ -54,17 +60,18 @@ let checkMobile = (req, res, next) => { |
|
|
}
|
|
|
|
|
|
// 判断手机号是否检查超过指定次数
|
|
|
let key = 'checkmobilenum_' + passportHelper.makeAreaMobile(area, mobile);
|
|
|
let regCheckKey = 'regCheckMobileNum_' + passportHelper.makeAreaMobile(area, mobile);
|
|
|
let checkNum = req.session[regCheckKey];
|
|
|
|
|
|
cache.get(key).then((checkNum) => {
|
|
|
checkNum = +(checkNum || 0);
|
|
|
req.session[regCheckKey] = ++checkNum;
|
|
|
|
|
|
cache.set(key, ++checkNum).catch(next);
|
|
|
if (checkNum > 500) {
|
|
|
data.message = '检查次数太多';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
|
|
|
// 判断用户是否存在
|
|
|
return userService.findByMobileAsync(area, mobile).then((user) => {
|
|
|
if (!_.isEmpty(user)) {
|
...
|
...
|
@@ -74,10 +81,12 @@ let checkMobile = (req, res, next) => { |
|
|
|
|
|
data.code = 200;
|
|
|
return res.json(data);
|
|
|
});
|
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 图形验证码校验
|
|
|
*/
|
|
|
let picCaptcha = (req, res) => {
|
|
|
let verifyCode = _.trim(req.body.verifyCode);
|
|
|
|
...
|
...
|
@@ -94,6 +103,9 @@ let picCaptcha = (req, res) => { |
|
|
});
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 发送验证码
|
|
|
*/
|
|
|
let sendBindMsg = (req, res, next) => {
|
|
|
let data = {
|
|
|
code: 400,
|
...
|
...
|
@@ -118,12 +130,13 @@ let sendBindMsg = (req, res, next) => { |
|
|
}
|
|
|
|
|
|
// 检查是否检查过
|
|
|
// let makeMobile = passportHelper.makeAreaMobile(area, mobile);
|
|
|
//
|
|
|
// if (req.session[`checkmobile_${makeMobile}`] !== makeMobile) {
|
|
|
// data.message = '发送失败';
|
|
|
// return res.json(data);
|
|
|
// }
|
|
|
let regCheckKey = 'regCheckMobileNum_' + passportHelper.makeAreaMobile(area, mobile);
|
|
|
let checkNum = req.session[regCheckKey];
|
|
|
|
|
|
if (!checkNum) {
|
|
|
data.message = '发送失败';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
// 校验是否发送过多
|
|
|
let sendCodeKey = `send_code_${area}_${mobile}`;
|
...
|
...
|
@@ -159,6 +172,9 @@ let sendBindMsg = (req, res, next) => { |
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 短信验证码校验
|
|
|
*/
|
|
|
let msgCaptcha = (req, res, next) => {
|
|
|
let data = {
|
|
|
code: 400,
|
...
|
...
|
@@ -186,6 +202,9 @@ let msgCaptcha = (req, res, next) => { |
|
|
}).catch(next);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 注册接口
|
|
|
*/
|
|
|
let mobileRegister = (req, res, next) => {
|
|
|
let data = {
|
|
|
code: 400,
|
...
|
...
|
|