use req.ip not x-forwarded-for to get ip address for multi currency

This commit is contained in:
Henry Oswald 2014-10-13 17:55:18 +01:00
parent 3382c5bb17
commit 6437f74cd3
2 changed files with 4 additions and 5 deletions

View file

@ -22,7 +22,7 @@ module.exports = SubscriptionController =
if req.query.v?
viewName = "#{viewName}_#{req.query.v}"
logger.log viewName:viewName, "showing plans page"
GeoIpLookup.getCurrencyCode req.headers["x-forwarded-for"], (err, recomendedCurrency)->
GeoIpLookup.getCurrencyCode req.ip, (err, recomendedCurrency)->
res.render viewName,
title: "plans_and_pricing"
plans: plans
@ -40,7 +40,7 @@ module.exports = SubscriptionController =
res.redirect "/user/subscription"
else
currency = req.query.currency?.toUpperCase()
GeoIpLookup.getCurrencyCode req.headers["x-forwarded-for"], (err, recomendedCurrency)->
GeoIpLookup.getCurrencyCode req.ip, (err, recomendedCurrency)->
if recomendedCurrency? and !currency?
currency = recomendedCurrency
RecurlyWrapper.sign {

View file

@ -81,15 +81,14 @@ describe "SubscriptionController sanboxed", ->
describe "plansPage", ->
beforeEach (done) ->
@req.headers =
"x-forwarded-for" : "1234.3123.3131.333 313.133.445.666 653.5345.5345.534"
@req.ip = "1234.3123.3131.333 313.133.445.666 653.5345.5345.534"
@GeoIpLookup.getCurrencyCode.callsArgWith(1, null, @stubbedCurrencyCode)
@res.callback = done
@SubscriptionController.plansPage(@req, @res)
it "should set the recommended currency from the geoiplookup", (done)->
@res.renderedVariables.recomendedCurrency.should.equal(@stubbedCurrencyCode)
@GeoIpLookup.getCurrencyCode.calledWith(@req.headers["x-forwarded-for"]).should.equal true
@GeoIpLookup.getCurrencyCode.calledWith(@req.ip).should.equal true
done()
describe "editBillingDetailsPage", ->