Authored by 毕凯

Merge branch 'hotfix/loginip' into 'release/5.5.1'

登录添加 IP



See merge request !444
... ... @@ -34,6 +34,7 @@ passport.use(new LocalStrategy({
}, (req, username, password, done) => {
let area = req.body.areaCode || '86';
let clientIp = req.yoho.clientIp || '';
if (isNaN(parseInt(area, 0)) || _.isEmpty(username) || _.isEmpty(password)) {
logger.info(`【Passport Loginbad params, area:${area} account:${username} password:${password}`);
... ... @@ -64,7 +65,7 @@ passport.use(new LocalStrategy({
let shoppingKey = cookie.getShoppingKey(req);
AuthHelper.signinAes(area, username, password, shoppingKey).then((result) => {
AuthHelper.signinAes(area, username, password, shoppingKey, clientIp).then((result) => {
if (result.code && result.code === 200 && result.data.uid) {
done(null, result.data);
} else {
... ...
... ... @@ -23,9 +23,9 @@ class Auth {
return api.post('', param);
}
static signinAes(area, profile, password, shoppingKey) {
static signinAes(area, profile, password, shoppingKey, ip) {
let param = {
method: 'app.passport.signinWebV2',
method: 'app.passport.signinAES',
area: area,
profile: profile,
password: aes.aesPwd(password)
... ... @@ -35,7 +35,12 @@ class Auth {
param.shopping_key = shoppingKey;
}
return api.post('', param);
return api.post('', param, {
headers: {
'user-agent': 'yoho/nodejs',
'X-YOHO-IP': ip
}
});
}
static signinByOpenID(nickname, openId, sourceType, shoppingKey) {
... ...
... ... @@ -5,8 +5,25 @@
*/
'use strict';
const _ = require('lodash');
const helpers = global.yoho.helpers;
/**
* 获取 IP
* @param {*} req
*/
const _getClientIp = req => {
let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || req.ip;
if (remoteIp.indexOf(',') > 0) {
let arr = remoteIp.split(',');
remoteIp = _.trim(arr[arr.length - 1]);
}
return remoteIp;
};
module.exports = () => {
return (req, res, next) => {
let yoho = {
... ... @@ -17,6 +34,9 @@ module.exports = () => {
const channel = req.query.channel || req.cookies._Channel || 'boys';
// IP 地址
yoho.clientIp = _getClientIp(req);
// 用于头部颜色控制
yoho.pageChannel[channel] = true;
... ...