Added GeoIP Helper to Signup
This commit is contained in:
@@ -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()) {
|
||||
|
||||
@@ -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 };
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user