...
|
...
|
@@ -9,10 +9,14 @@ |
|
|
|
|
|
const helpers = require(global.library + '/helpers');
|
|
|
const sign = require(global.library + '/sign');
|
|
|
const config = require('../../../config/common');
|
|
|
const RegService = require('../models/reg-service');
|
|
|
const _ = require('lodash');
|
|
|
|
|
|
const reg = {
|
|
|
_verifyToken: (token) => {
|
|
|
return token;
|
|
|
},
|
|
|
index: (req, res) => {
|
|
|
// 设置注册有效时间30分钟, 防机器刷
|
|
|
req.session._REG_EXPIRE = Date.now() + 1800000;
|
...
|
...
|
@@ -25,7 +29,6 @@ const reg = { |
|
|
|
|
|
res.render('reg/index', {
|
|
|
title: '注册',
|
|
|
regIndex: true, // 模板中使用JS的标识
|
|
|
backUrl: 'javascript:history.go(-1)', // eslint-disable-line
|
|
|
headerText: '注册', // 头部信息
|
|
|
isPassportPage: true, // 模板中模块标识
|
...
|
...
|
@@ -40,7 +43,6 @@ const reg = { |
|
|
data: ''
|
|
|
};
|
|
|
|
|
|
|
|
|
let mobile = +req.body.phoneNum;
|
|
|
let area = +(req.body.areaCode || 86);
|
|
|
|
...
|
...
|
@@ -78,6 +80,60 @@ const reg = { |
|
|
return res.json(result);
|
|
|
}).catch(next);
|
|
|
},
|
|
|
code: (req, res, next) => {
|
|
|
let token = req.query.token;
|
|
|
let mobile = +req.query.phoneNum;
|
|
|
let area = +(req.query.areaCode || 86);
|
|
|
|
|
|
// 判断是否允许访问, 不允许则跳转到错误页面
|
|
|
if (!_.isString(token) || !_.isNumber(mobile) || !sign.verifyToken(mobile, token)) {
|
|
|
return next({
|
|
|
code: 403,
|
|
|
message: 'error token or mobile'
|
|
|
});
|
|
|
}
|
|
|
|
|
|
res.render('reg/code', {
|
|
|
page: 'code',
|
|
|
title: '注册-验证码',
|
|
|
backUrl: config.siteUrl + '/?go=1', // eslint-disable-line
|
|
|
headerText: '注册', // 头部信息
|
|
|
isPassportPage: true, // 模板中模块标识
|
|
|
areaCode: area, // 默认的区号
|
|
|
phoneNum: mobile, // 手机号
|
|
|
token: token, // 访问令牌
|
|
|
serviceUrl: 'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&configID=149091&jid=8732423409&info=' // 在线客服
|
|
|
});
|
|
|
},
|
|
|
sendcode: (req, res, next) => {
|
|
|
let data = {
|
|
|
code: 400,
|
|
|
message: '发送验证码失败',
|
|
|
data: ''
|
|
|
};
|
|
|
|
|
|
let mobile = +req.body.phoneNum;
|
|
|
let area = +(req.body.areaCode || 86);
|
|
|
|
|
|
/* 判断参数是否合法 */
|
|
|
if (!_.isNumber(mobile) || !_.isNumber(area)) {
|
|
|
data.message = '手机号错误';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 设置注册有效时间30分钟, 防机器刷 */
|
|
|
let expire = req.session._REG_EXPIRE;
|
|
|
|
|
|
if (!expire || expire < Date.now()) {
|
|
|
data.message = '非法请求';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 向手机发送注册验证码 */
|
|
|
RegService.sendCodeToMobile(area, mobile).then((result) => {
|
|
|
return result.code ? res.json(result) : res.json(data);
|
|
|
}).catch(next);
|
|
|
},
|
|
|
verifycode: (req, res, next) => {
|
|
|
let data = {
|
|
|
code: 400,
|
...
|
...
|
@@ -85,12 +141,13 @@ const reg = { |
|
|
data: ''
|
|
|
};
|
|
|
|
|
|
let mobile = req.body.phoneNum;
|
|
|
let area = req.body.areaCode;
|
|
|
let code = req.body.code;
|
|
|
let mobile = +req.body.phoneNum;
|
|
|
let area = +(req.body.areaCode || 86);
|
|
|
let code = +req.body.code;
|
|
|
|
|
|
/* 判断参数是否合法 */
|
|
|
if (!_.isNumber(mobile) || !_.isNumber(area)) {
|
|
|
if (!_.isNumber(mobile) || !_.isNumber(area) || !_.isNumber(code)) {
|
|
|
data.message = '手机号错误';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -98,6 +155,7 @@ const reg = { |
|
|
let expire = req.session._REG_EXPIRE;
|
|
|
|
|
|
if (!expire || expire < Date.now()) {
|
|
|
data.message = '非法请求';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
...
|
...
|
|