Showing
3 changed files
with
26 additions
and
3 deletions
@@ -34,7 +34,7 @@ passport.use(new LocalStrategy({ | @@ -34,7 +34,7 @@ passport.use(new LocalStrategy({ | ||
34 | }, (req, username, password, done) => { | 34 | }, (req, username, password, done) => { |
35 | 35 | ||
36 | let area = req.body.areaCode || '86'; | 36 | let area = req.body.areaCode || '86'; |
37 | - let ip = req.ip || ''; | 37 | + let clientIp = req.yoho.clientIp || ''; |
38 | 38 | ||
39 | if (isNaN(parseInt(area, 0)) || _.isEmpty(username) || _.isEmpty(password)) { | 39 | if (isNaN(parseInt(area, 0)) || _.isEmpty(username) || _.isEmpty(password)) { |
40 | logger.info(`【Passport Login】bad params, area:${area} account:${username} password:${password}`); | 40 | logger.info(`【Passport Login】bad params, area:${area} account:${username} password:${password}`); |
@@ -65,7 +65,7 @@ passport.use(new LocalStrategy({ | @@ -65,7 +65,7 @@ passport.use(new LocalStrategy({ | ||
65 | 65 | ||
66 | let shoppingKey = cookie.getShoppingKey(req); | 66 | let shoppingKey = cookie.getShoppingKey(req); |
67 | 67 | ||
68 | - AuthHelper.signinAes(area, username, password, shoppingKey, ip).then((result) => { | 68 | + AuthHelper.signinAes(area, username, password, shoppingKey, clientIp).then((result) => { |
69 | if (result.code && result.code === 200 && result.data.uid) { | 69 | if (result.code && result.code === 200 && result.data.uid) { |
70 | done(null, result.data); | 70 | done(null, result.data); |
71 | } else { | 71 | } else { |
@@ -5,8 +5,25 @@ | @@ -5,8 +5,25 @@ | ||
5 | */ | 5 | */ |
6 | 6 | ||
7 | 'use strict'; | 7 | 'use strict'; |
8 | +const _ = require('lodash'); | ||
8 | const helpers = global.yoho.helpers; | 9 | const helpers = global.yoho.helpers; |
9 | 10 | ||
11 | +/** | ||
12 | + * 获取 IP | ||
13 | + * @param {*} req | ||
14 | + */ | ||
15 | +const _getClientIp = req => { | ||
16 | + let remoteIp = req.get('X-Forwarded-For') || req.get('X-Real-IP') || req.ip; | ||
17 | + | ||
18 | + if (remoteIp.indexOf(',') > 0) { | ||
19 | + let arr = remoteIp.split(','); | ||
20 | + | ||
21 | + remoteIp = _.trim(arr[arr.length - 1]); | ||
22 | + } | ||
23 | + | ||
24 | + return remoteIp; | ||
25 | +}; | ||
26 | + | ||
10 | module.exports = () => { | 27 | module.exports = () => { |
11 | return (req, res, next) => { | 28 | return (req, res, next) => { |
12 | let yoho = { | 29 | let yoho = { |
@@ -17,6 +34,9 @@ module.exports = () => { | @@ -17,6 +34,9 @@ module.exports = () => { | ||
17 | 34 | ||
18 | const channel = req.query.channel || req.cookies._Channel || 'boys'; | 35 | const channel = req.query.channel || req.cookies._Channel || 'boys'; |
19 | 36 | ||
37 | + // IP 地址 | ||
38 | + yoho.clientIp = _getClientIp(req); | ||
39 | + | ||
20 | // 用于头部颜色控制 | 40 | // 用于头部颜色控制 |
21 | yoho.pageChannel[channel] = true; | 41 | yoho.pageChannel[channel] = true; |
22 | 42 |
-
Please register or login to post a comment