diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj
index cab841f6..9e68995d 100644
--- a/Logic/Logic.csproj
+++ b/Logic/Logic.csproj
@@ -49,6 +49,14 @@
false
+
+ ..\packages\NGeoIP.1.0.1\lib\net45\AutoMapper.dll
+ True
+
+
+ ..\packages\NGeoIP.1.0.1\lib\net45\AutoMapper.Net4.dll
+ True
+
..\External Libraries\HtmlAgilityPack.dll
@@ -60,6 +68,10 @@
False
..\External Dependencies\bin\NBitcoin.dll
+
+ ..\packages\RestSharp.104.2.0\lib\net4\RestSharp.dll
+ True
+
False
..\External Libraries\Starksoft.Cryptography.OpenPGP.dll
@@ -679,6 +691,10 @@
+
+ AutoMapper.Net4.dll
+ PreserveNewest
+
diff --git a/Logic/packages.config b/Logic/packages.config
index 4a7f1074..284ffcd9 100644
--- a/Logic/packages.config
+++ b/Logic/packages.config
@@ -1,5 +1,8 @@
+
+
+
\ No newline at end of file
diff --git a/Site5/Pages/v5/Public/Signup.aspx b/Site5/Pages/v5/Public/Signup.aspx
index 98c17c3c..b5847ae1 100644
--- a/Site5/Pages/v5/Public/Signup.aspx
+++ b/Site5/Pages/v5/Public/Signup.aspx
@@ -129,8 +129,21 @@
// but ASP.Net server-side includes don't work well, and a JavaScript include isn't compatible with the
// ASP.Net inline evaluations.
- $(document).ready(function () {
- UpdatePostalPrefix('XX', $('#<%= DropCountries.ClientID %>').val());
+ $(document).ready(function () {
+
+ SwarmopsJS.ajaxCall("/Pages/v5/Public/Signup.aspx/GuessCountry", {}, function(result) {
+ if (result.Success) {
+ alert(result.DisplayMessage);
+ $('#<%=this.DropCountries.ClientID%>').val(result.DisplayMessage);
+ } else {
+ // No dice for some reason - initialize postal codes with default lookup
+ // (the change-of-field in the success scenario triggers this in that case)
+ UpdatePostalPrefix('XX', $('#<%= DropCountries.ClientID %>').val());
+ }
+ });
+
+
+
$('#<%= TextPostal.ClientID %>').on('input', function () {
if (CheckPostalCode()) {
diff --git a/Site5/Pages/v5/Public/Signup.aspx.cs b/Site5/Pages/v5/Public/Signup.aspx.cs
index 8ca71624..be23421d 100644
--- a/Site5/Pages/v5/Public/Signup.aspx.cs
+++ b/Site5/Pages/v5/Public/Signup.aspx.cs
@@ -7,6 +7,8 @@ using System.Web.Security;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
+using NGeoIP;
+using NGeoIP.Client;
using Resources;
using Swarmops.Common.Enums;
using Swarmops.Logic.Communications;
@@ -278,5 +280,36 @@ namespace Swarmops.Frontend.Pages.Public
return new AjaxCallResult {Success = false};
}
+
+ [WebMethod]
+ public static AjaxCallResult GuessCountry()
+ {
+ // IMPORTANT: If you're implementing a sensitive organization, this should use YOUR OWN geoip server and not freegeoip.com, which
+ // may potentially be eavesdroppable. Look at the freegeoip.com for how to download their database.
+
+ if (HttpContext.Current.Request.UserHostAddress == "::1")
+ {
+ // yeah, we're running from localhost, no big point trying to geoip this
+ return new AjaxCallResult {Success = false};
+ }
+
+ try
+ {
+ NGeoIP.Request request = new Request()
+ {
+ Format = Format.Json,
+ IP = HttpContext.Current.Request.UserHostAddress
+ };
+ NGeoClient client = new NGeoClient (request);
+ NGeoIP.RawData rawData = client.Execute();
+
+ return new AjaxCallResult {Success = true, DisplayMessage = rawData.CountryCode};
+ }
+ catch (Exception)
+ {
+ return new AjaxCallResult { Success = false };
+ }
+
+ }
}
}
\ No newline at end of file
diff --git a/Site5/packages.config b/Site5/packages.config
index 4a7f1074..284ffcd9 100644
--- a/Site5/packages.config
+++ b/Site5/packages.config
@@ -1,5 +1,8 @@
+
+
+
\ No newline at end of file