This commit is contained in:
Rick Falkvinge
2015-05-21 10:53:08 +02:00
5 changed files with 70 additions and 2 deletions
+16
View File
@@ -49,6 +49,14 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=3.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\NGeoIP.1.0.1\lib\net45\AutoMapper.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="AutoMapper.Net4, Version=3.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>..\packages\NGeoIP.1.0.1\lib\net45\AutoMapper.Net4.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="HtmlAgilityPack">
<HintPath>..\External Libraries\HtmlAgilityPack.dll</HintPath>
</Reference>
@@ -60,6 +68,10 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Dependencies\bin\NBitcoin.dll</HintPath>
</Reference>
<Reference Include="RestSharp, Version=104.2.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.104.2.0\lib\net4\RestSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Starksoft.Cryptography.OpenPGP, Version=1.0.140.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\External Libraries\Starksoft.Cryptography.OpenPGP.dll</HintPath>
@@ -679,6 +691,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<Content Include="..\packages\AutoMapper.3.1.1\lib\net40\AutoMapper.Net4.dll">
<Link>AutoMapper.Net4.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Resources\SourceResourceFiles.txt" />
</ItemGroup>
<ItemGroup>
+3
View File
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.1.1" targetFramework="net45" />
<package id="Microsoft.Tpl.Dataflow" version="4.5.9" targetFramework="net45" />
<package id="NGeoIP" version="1.0.1" targetFramework="net45" />
<package id="RestSharp" version="104.2.0" targetFramework="net45" />
<package id="vtortola.WebSocketListener" version="2.1.5.0" targetFramework="net45" />
</packages>
+15 -2
View File
@@ -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()) {
+33
View File
@@ -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 };
}
}
}
}
+3
View File
@@ -1,5 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="3.1.1" targetFramework="net45" />
<package id="Microsoft.Tpl.Dataflow" version="4.5.9" targetFramework="net45" />
<package id="NGeoIP" version="1.0.1" targetFramework="net45" />
<package id="RestSharp" version="104.2.0" targetFramework="net45" />
<package id="vtortola.WebSocketListener" version="2.1.5.0" targetFramework="net45" />
</packages>