Authored by 郭成尧

login-ip-modified

... ... @@ -34,7 +34,7 @@ passport.use(new LocalStrategy({
}, (req, username, password, done) => {
let area = req.body.areaCode || '86';
let ip = req.ip || '';
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}`);
... ... @@ -65,7 +65,7 @@ passport.use(new LocalStrategy({
let shoppingKey = cookie.getShoppingKey(req);
AuthHelper.signinAes(area, username, password, shoppingKey, ip).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 {
... ...
... ... @@ -36,7 +36,10 @@ class Auth {
}
return api.post('', param, {
headers: {'X-Forwarded-For': ip}
headers: {
'user-agent': 'yoho/nodejs',
'X-YOHO-IP': ip
}
});
}
... ...
... ... @@ -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;
... ...