...
|
...
|
@@ -15,7 +15,7 @@ const RegService = require('../models/reg-service'); |
|
|
const AuthHelper = require('../models/auth-helper');
|
|
|
|
|
|
let index = (req, res) => {
|
|
|
// 设置注册有效时间30分钟, 防机器刷
|
|
|
// 设置注册有效时间30分钟, 防机器刷
|
|
|
req.session._REG_EXPIRE = Date.now() + 1800000;
|
|
|
|
|
|
let refer = req.query.refer;
|
...
|
...
|
@@ -43,13 +43,13 @@ let verifyMobile = (req, res, next) => { |
|
|
let mobile = +req.body.phoneNum;
|
|
|
let area = +(req.body.areaCode || 86);
|
|
|
|
|
|
/* 判断参数是否合法 */
|
|
|
// 判断参数是否合法
|
|
|
if (!_.isNumber(mobile) || !_.isNumber(area)) {
|
|
|
data.message = '手机号错误';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 设置注册有效时间30分钟, 防机器刷 */
|
|
|
// 设置注册有效时间30分钟, 防机器刷
|
|
|
let expire = req.session._REG_EXPIRE;
|
|
|
|
|
|
if (!expire || expire < Date.now()) {
|
...
|
...
|
@@ -57,13 +57,13 @@ let verifyMobile = (req, res, next) => { |
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 向手机发送注册验证码 */
|
|
|
// 向手机发送注册验证码
|
|
|
RegService.sendCodeToMobile(area, mobile).then((result) => {
|
|
|
if (!result.code) {
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 返回跳转到验证页面的链接 */
|
|
|
// 返回跳转到验证页面的链接
|
|
|
if (result.code === 200) {
|
|
|
let token = sign.makeToken(mobile);
|
|
|
|
...
|
...
|
@@ -82,7 +82,7 @@ let codeAction = (req, res, next) => { |
|
|
let mobile = +req.query.phoneNum;
|
|
|
let area = +(req.query.areaCode || 86);
|
|
|
|
|
|
// 判断是否允许访问, 不允许则跳转到错误页面
|
|
|
// 判断是否允许访问, 不允许则跳转到错误页面
|
|
|
if (!_.isString(token) || !_.isNumber(mobile) || !sign.verifyToken(mobile, token)) {
|
|
|
return next({
|
|
|
code: 403,
|
...
|
...
|
@@ -112,13 +112,13 @@ let sendCode = (req, res, next) => { |
|
|
let mobile = +req.body.phoneNum;
|
|
|
let area = +(req.body.areaCode || 86);
|
|
|
|
|
|
/* 判断参数是否合法 */
|
|
|
// 判断参数是否合法
|
|
|
if (!_.isNumber(mobile) || !_.isNumber(area)) {
|
|
|
data.message = '手机号错误';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 设置注册有效时间30分钟, 防机器刷 */
|
|
|
// 设置注册有效时间30分钟, 防机器刷
|
|
|
let expire = req.session._REG_EXPIRE;
|
|
|
|
|
|
if (!expire || expire < Date.now()) {
|
...
|
...
|
@@ -126,7 +126,7 @@ let sendCode = (req, res, next) => { |
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 向手机发送注册验证码 */
|
|
|
// 向手机发送注册验证码
|
|
|
RegService.sendCodeToMobile(area, mobile).then((result) => {
|
|
|
return result.code ? res.json(result) : res.json(data);
|
|
|
}).catch(next);
|
...
|
...
|
@@ -148,7 +148,7 @@ let verifyCode = (req, res, next) => { |
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 设置注册有效时间30分钟, 防机器刷 */
|
|
|
// 设置注册有效时间30分钟, 防机器刷
|
|
|
let expire = req.session._REG_EXPIRE;
|
|
|
|
|
|
if (!expire || expire < Date.now()) {
|
...
|
...
|
@@ -156,13 +156,13 @@ let verifyCode = (req, res, next) => { |
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 验证注册的标识码是否有效 */
|
|
|
// 验证注册的标识码是否有效
|
|
|
RegService.validMobileCode(area, mobile, code).then((result) => {
|
|
|
if (!result.code) {
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 返回跳转到设置密码的链接 */
|
|
|
// 返回跳转到设置密码的链接
|
|
|
if (result.code === 200) {
|
|
|
let token = sign.makeToken(mobile);
|
|
|
|
...
|
...
|
@@ -183,7 +183,7 @@ let passwordAction = (req, res, next) => { |
|
|
let mobile = +req.query.phoneNum;
|
|
|
let area = +(req.query.areaCode || 86);
|
|
|
|
|
|
// 判断是否允许访问, 不允许则跳转到错误页面
|
|
|
// 判断是否允许访问, 不允许则跳转到错误页面
|
|
|
if (!_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !sign.verifyToken(mobile, token)) {
|
|
|
return next({
|
|
|
code: 403,
|
...
|
...
|
@@ -214,27 +214,27 @@ let setPassword = (req, res, next) => { |
|
|
let password = req.body.password;
|
|
|
let token = req.body.token;
|
|
|
|
|
|
/* 判断参数是否合法 */
|
|
|
// 判断参数是否合法
|
|
|
if (!_.isString(token) || !_.isNumber(mobile) || !_.isNumber(area) || !password) {
|
|
|
data.message = '请求参数不合法';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 判断是否允许访问 */
|
|
|
// 判断是否允许访问
|
|
|
if (!sign.verifyToken(mobile, token)) {
|
|
|
data.message = '非法 token';
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
/* 判断密码是否符合规则 */
|
|
|
// 判断密码是否符合规则
|
|
|
if (!helpers.verifyPassword(password)) {
|
|
|
return res.json(data);
|
|
|
}
|
|
|
|
|
|
// 购物车key
|
|
|
// 购物车key
|
|
|
let shoppingKey = cookie.getShoppingKey(req);
|
|
|
|
|
|
// 验证注册的标识码是否有效
|
|
|
// 验证注册的标识码是否有效
|
|
|
RegService.regMobile(area, mobile, password, shoppingKey).then((result) => {
|
|
|
if (!result.code || result.code !== 200) {
|
|
|
return Promise.reject(result);
|
...
|
...
|
@@ -245,7 +245,7 @@ let setPassword = (req, res, next) => { |
|
|
|
|
|
return AuthHelper.syncUserSession(result.data.uid, req, res);
|
|
|
}).then(() => {
|
|
|
// 返回跳转到来源页面
|
|
|
// 返回跳转到来源页面
|
|
|
let refer = req.cookies.refer;
|
|
|
|
|
|
if (refer) {
|
...
|
...
|
|