Authored by htoooth

Merge remote-tracking branch 'origin/feature/passport' into feature/passport

... ... @@ -2,11 +2,14 @@
* 注册控制器
*/
'use strict';
const _ = require('lodash');
const passportHelper = require('../models/passport-helper');
const regService = require('../models/reg-service');
const userService = require('../models/user-service');
const config = require('../../../config/common');
let helpers = global.yoho.helpers;
let cache = global.yoho.cache;
let index = (req, res, next) => {
// 设置注册有效时间30分钟, 防机器刷
... ... @@ -36,6 +39,43 @@ let index = (req, res, next) => {
}).catch(next);
};
let checkMobile = (req, res, next) => {
let data = {
code: 400
};
let mobile = +req.body.mobile;
let area = +req.body.area;
if (!_.isNumber(mobile) || !_.isNumber(area)) {
data.message = '手机号码格式不正确';
return res.json(data);
}
// 判断手机号是否检查超过指定次数
let key = 'checkmobilenum_' + passportHelper.makeAreaMobile(area, mobile);
cache.get(key).then((checkNum) => {
checkNum = +(checkNum || 0);
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)) {
data.message = '手机号码已经存在';
return res.json(data);
}
data.code = 200;
return res.json(data);
});
}).catch(next);
};
let success = (req, res, next) => {
let goUrl = req.query.next || config.siteUrl;
let goShoppingUrl = req.query.goShoppingUrl || config.siteUrl;
... ... @@ -55,5 +95,6 @@ let success = (req, res, next) => {
module.exports = {
index,
success
success,
checkMobile
};
... ...
... ... @@ -16,18 +16,15 @@ const findByMobileAsync = (area, mobile) => {
mobile: mobile,
area: area,
method: 'app.passport.getProfileByMobile'
})
.then(result => {
if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
return EMPTY;
}
return result.data;
})
.catch(() => {
}).then(result => {
if (!result.code || result.code !== 200 || !result.data || _.isEmpty(result.data)) {
return EMPTY;
});
}
return result.data;
}).catch(() => {
return EMPTY;
});
};
/**
... ...
... ... @@ -23,7 +23,7 @@ router.get('/login/wechat/callback', login.wechat.callback);
* 注册页面路由
*/
router.get('/reg/index', reg.index);
router.post('/reg/checkmobile', reg.checkMobile);
router.get('/reg/success', reg.success);
/**
... ...
... ... @@ -21,9 +21,9 @@ module.exports = {
useOneapm: false,
useCache: false,
memcache: {
master: ['192.168.102.163:11213'],
slave: ['192.168.102.163:11213'],
session: ['192.168.102.161:11213'],
master: ['192.168.102.222:11213'],
slave: ['192.168.102.222:11213'],
session: ['192.168.102.222:11213'],
timeout: 1000,
retries: 0
},
... ...
var reg = require('./reg/reg');
reg.init();
reg.init('reg');
... ...
... ... @@ -116,7 +116,7 @@ function phoneAjaxFn(page, callback) {
data;
if (page === 'reg') {
url = '/passport/register/checkmobile';
url = '/passport/reg/checkmobile';
data = {
mobile: $pn.val(),
area: $region.text().split('+')[1]
... ...
... ... @@ -447,7 +447,7 @@
}
/* 高级选项箭头位置IE11Hack */
_:-ms-fullscreen,
_:-ms-fullscreen, /* stylelint-disable-line */
:root .senior-up-icon {
top: 1px;
}
... ...