Authored by ccbikai

增加注册验证码页面

... ... @@ -12,9 +12,6 @@ const helpers = require(`${library}/helpers`);
const service = require('../models/back-service');
// 本地地址 localhost
helpers.urlFormat = helpers.fakeUrlFormat;
const SIGN_IN_URL = helpers.urlFormat('/signin.html');
/**
... ... @@ -303,4 +300,3 @@ module.exports.setNewPasswordByMobileAPI = (req, res) => {
res.json(result);
}).catch(() => res.json({code: 400, message: '修改密码失败'}));
};
... ...
... ... @@ -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);
}
... ...
... ... @@ -54,6 +54,9 @@ router.post('/bind/changeMobile', bind.changeMobile);
*/
router.get('/reg/index', reg.index);
router.post('/reg/verifymobile', reg.verifymobile);
router.get('/reg/code', reg.code);
router.post('/reg/sendcode', reg.sendcode);
router.post('/reg/verifycode', reg.verifycode);
/**
* 邮箱
... ...
{{> layout/header}}
<div class="reg-code-page passport-page yoho-page">
{{> passport/code}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="reg-password-page passport-page yoho-page">
{{> passport/header}}
<div class="content">
... ... @@ -11,13 +10,3 @@
<input id="area-code" type="hidden" value="{{areaCode}}">
<input id="token" type="hidden" value="{{token}}">
</div>
<script type='text/javascript'>
(function(a,b,c,d){
a[c]=function(){a[c]['ar']=a[c]['ar']||[];a[c]['ar'].push(arguments);};
var s=b.createElement('script');s.async = 1;s.src='//t.agrantsem.com/js/agt.js';
var r=b.getElementsByTagName('script')[0];r.parentNode.insertBefore(s,r);
})(window,document,'_agtjs','script');
_agtjs('init','AG_052186_PHCW','yohobuy.com');
_agtjs('loadEvent',{atsev:101,'atsrmv':""});
</script>
{{> layout/footer}}
\ No newline at end of file
... ...
... ... @@ -76,41 +76,6 @@ exports.urlFormat = (uri, qs, module) => {
};
/**
* 站内地址格式化
* @param {[string]} uri 路径
* @param {[object]} qs 查询字符串
* @param {[string]} module 模块
* @return {[string]}
*/
exports.fakeUrlFormat = (uri, qs, module) => {
const subDomain = 'http://localhost:6001';
const subName = {
default: subDomain,
guang: `${subDomain}`,
list: `${subDomain}`,
search: `${subDomain}`,
huodong: `${subDomain}`,
index: subDomain
};
let url;
module = module || 'default';
if (subName[module]) {
url = subName[module];
} else {
url = `//${module}${subDomain}`; // 规则没匹配到就把模块当作子域名
}
url += uri;
if (qs) {
url += `?${querystring.stringify(qs)}`;
}
return url;
};
/**
* 大写转小写处理
* @param {[string]} str 转换字符
*/
... ...
... ... @@ -95,6 +95,12 @@ exports.webSign = (params) => {
return params.key === md5(md5(webPrivateKey) + params.uid);
};
// 生成 token
exports.makeToken = (string) => {
return md5(md5(string + '#@!@#'));
};
// 校验 token
exports.verifyToken = (string, token) => {
return exports.makeToken(string) === token;
};
... ...
... ... @@ -23,7 +23,7 @@ module.exports = function(useInRegister, useForBind, useForRelate) {
var urlMid = useInRegister ? 'reg' : 'back';
var isReg = parseInt($('#isReg').val());
var isReg = parseInt($('#isReg').val(), 10);
function startBind() {
$.ajax({
... ...
require('./register/code');
... ...