diff --git a/Site5/Pages/v5/Init/Default.aspx.cs b/Site5/Pages/v5/Init/Default.aspx.cs
index 2bcaaf38..f903fcb5 100644
--- a/Site5/Pages/v5/Init/Default.aspx.cs
+++ b/Site5/Pages/v5/Init/Default.aspx.cs
@@ -13,20 +13,20 @@ using System.Web.UI;
using Resources;
using Swarmops.Basic.Enums;
using Swarmops.Database;
+using Swarmops.Logic.Cache;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
-using Swarmops.Site.Automation;
-using City = Swarmops.Site.Automation.City;
-using Country = Swarmops.Site.Automation.Country;
-using Geography = Swarmops.Site.Automation.Geography;
-using PostalCode = Swarmops.Site.Automation.PostalCode;
+using Swarmops.Logic.Automation;
+using City = Swarmops.Logic.Automation.City;
+using Country = Swarmops.Logic.Automation.Country;
+using Geography = Swarmops.Logic.Automation.Geography;
+using PostalCode = Swarmops.Logic.Automation.PostalCode;
public partial class Pages_v5_Init_Default : Page
{
- private static string _buildIdentity;
private static SwarmDb.Credentials _testReadCredentials;
private static SwarmDb.Credentials _testWriteCredentials;
private static SwarmDb.Credentials _testAdminCredentials;
@@ -170,28 +170,6 @@ public partial class Pages_v5_Init_Default : Page
}
- private string GetBuildIdentity()
- {
- // Read build number if not loaded, or set to "Private" if none
-
- if (_buildIdentity == null)
- {
- try
- {
- using (StreamReader reader = File.OpenText (HttpContext.Current.Request.MapPath ("~/BuildIdentity.txt"))
- )
- {
- _buildIdentity = "Build " + reader.ReadLine();
- }
- }
- catch (Exception)
- {
- _buildIdentity = "Private Build";
- }
- }
-
- return _buildIdentity;
- }
[WebMethod]
public static PermissionsAnalysis FirstCredentialsTest
@@ -383,7 +361,7 @@ public partial class Pages_v5_Init_Default : Page
DatabaseMaintenance.FirstInitialization();
- _initProgress = 6;
+ _initProgress = 3;
_initMessage = "Applying all post-baseline database schema upgrades...";
DatabaseMaintenance.UpgradeSchemata();
Thread.Sleep (100);
@@ -394,10 +372,7 @@ public partial class Pages_v5_Init_Default : Page
// Create translation lists
- Dictionary
geographyIdTranslation = new Dictionary();
- Dictionary cityIdTranslation = new Dictionary();
Dictionary countryIdTranslation = new Dictionary();
- Dictionary cityIdsUsedLookup = new Dictionary();
// Initialize the root geography (which becomes #1 if everything works)
@@ -422,7 +397,7 @@ public partial class Pages_v5_Init_Default : Page
countryIdTranslation[country.Code] = SwarmDb.GetDatabaseForWriting().CreateCountry (country.Name,
country.Code,
country.Culture,
- rootGeographyId, 5,
+ rootGeographyId, country.PostalCodeLength,
string.Empty);
count++;
@@ -452,142 +427,10 @@ public partial class Pages_v5_Init_Default : Page
{
// Get the geography layout
- _initMessage = "Retrieving geography for " + countryCode + "...";
+ _initMessage = "Initializing geography for " + countryCode + "... ";
Thread.Sleep (100);
- Geography geography = geoDataFetcher.GetGeographyForCountry (countryCode);
-
- _initProgress = 10 + (int) (countryCount*initStepPerCountry + initStepPerCountry/6);
- _initMessage = "Setting up geography for " + countryCode + "...";
- Thread.Sleep (100);
-
- // Create the country's root geography
-
- int countryRootGeographyId = SwarmDb.GetDatabaseForWriting().CreateGeography (geography.Name,
- rootGeographyId);
- geographyIdTranslation[geography.GeographyId] = countryRootGeographyId;
- SwarmDb.GetDatabaseForWriting().SetCountryGeographyId (countryIdTranslation[countryCode],
- countryRootGeographyId);
-
- count = 0;
- total = InitDatabaseThreadCountGeographyChildren (geography.Children);
-
- InitDatabaseThreadCreateGeographyChildren (geography.Children, countryRootGeographyId,
- ref geographyIdTranslation, countryCode, ref count, total);
-
- _initProgress = 10 + (int) (countryCount*initStepPerCountry + initStepPerCountry/3);
- _initMessage = "Retrieving cities for " + countryCode + "...";
- Thread.Sleep (100);
-
- // Get the postal codes and cities
-
- City[] cities = null;
-
- try
- {
- cities = geoDataFetcher.GetCitiesForCountry (countryCode);
- }
- catch (Exception)
- // This is a SoapHeaderException in VS debugging, but SOMETHING ELSE! in Mono runtime, so make it generic
- {
- // This is typically a country that isn't populated with cities yet. Ignore.
- countryCount++;
- continue;
- }
-
-
- _initProgress = 10 + (int) (countryCount*initStepPerCountry + initStepPerCountry/2);
- _initMessage = "Retrieving postal codes for " + countryCode + "...";
- Thread.Sleep (100);
-
- PostalCode[] postalCodes = geoDataFetcher.GetPostalCodesForCountry (countryCode);
-
- // Find which cities are actually used
-
- foreach (PostalCode postalCode in postalCodes)
- {
- cityIdsUsedLookup[postalCode.CityId] = true;
- }
-
- _initProgress = 10 + (int) (countryCount*initStepPerCountry + initStepPerCountry*2/3);
-
- // Insert cities
-
- int newCountryId = countryIdTranslation[countryCode];
-
- int cityIdHighwater =
- SwarmDb.GetDatabaseForAdmin().ExecuteAdminCommandScalar ("SELECT Max(CityId) FROM Cities;");
-
- _initMessage = string.Format ("Setting up {0:N0} cities for {1}...", cities.Length, countryCode);
-
- StringBuilder sqlCityBuild =
- new StringBuilder ("INSERT INTO Cities (CityName, GeographyId, CountryId, Comment) VALUES ", 65536);
- bool insertComma = false;
-
- foreach (City city in cities)
- {
- if (!geographyIdTranslation.ContainsKey (city.GeographyId))
- {
- cityIdsUsedLookup[city.CityId] = false; // force non-use of invalid city
- }
-
- if (cityIdsUsedLookup[city.CityId])
- {
- int newGeographyId = geographyIdTranslation[city.GeographyId];
-
- if (insertComma)
- {
- sqlCityBuild.Append (",");
- }
-
- sqlCityBuild.Append ("('" + city.Name.Replace ("'", "\'") + "'," + newGeographyId + "," +
- newCountryId + ",'')");
- insertComma = true;
-
- cityIdTranslation[city.CityId] = ++cityIdHighwater; // Note that we assume the assigned ID here.
- }
- }
-
- sqlCityBuild.Append (";");
-
- SwarmDb.GetDatabaseForAdmin().ExecuteAdminCommand (sqlCityBuild.ToString());
- // Inserts all cities in one bulk op, to save roundtrips
-
- // Insert postal codes
-
- _initProgress = 10 + (int) (countryCount*initStepPerCountry + initStepPerCountry*5/6);
- _initMessage = string.Format ("Setting up {0:N0} postal codes for {1}...", postalCodes.Length,
- countryCode);
-
- StringBuilder sqlBuild =
- new StringBuilder ("INSERT INTO PostalCodes (PostalCode, CityId, CountryId) VALUES ", 65536);
- insertComma = false;
-
- foreach (PostalCode postalCode in postalCodes)
- {
- if (cityIdsUsedLookup[postalCode.CityId] == false)
- {
- // Remnants of invalid pointers
-
- continue;
- }
-
- int newCityId = cityIdTranslation[postalCode.CityId];
-
- if (insertComma)
- {
- sqlBuild.Append (",");
- }
-
- sqlBuild.Append ("('" + postalCode.PostalCode.Replace ("'", "\'") + "'," + newCityId + "," +
- newCountryId + ")");
- insertComma = true;
- }
-
- sqlBuild.Append (";");
-
- SwarmDb.GetDatabaseForAdmin().ExecuteAdminCommand (sqlBuild.ToString());
- // Inserts all postal codes in one bulk op, to save roundtrips
+ GeographyUpdate.PrimeCountry (countryCode);
countryCount++;
@@ -597,12 +440,13 @@ public partial class Pages_v5_Init_Default : Page
// Set Geography at baseline (TODO: Ask for what baseline we got)
Persistence.Key["LastGeographyUpdateId"] = "0";
+ Persistence.Key["LastGeographyUpdate"] = "1900-01-01";
// Set an installation ID
Persistence.Key["SwarmopsInstallationId"] = Guid.NewGuid().ToString();
- // Create initial currencies (European)
+ // Create initial currencies (European et al)
Currency.Create ("EUR", "Euros", "€");
Currency.Create ("USD", "US Dollars", "$");
@@ -634,42 +478,6 @@ public partial class Pages_v5_Init_Default : Page
Thread.Sleep (1000); // give some time for static var to stick and web interface to react before killing thread
}
- private static int InitDatabaseThreadCountGeographyChildren (Geography[] children)
- {
- int count = 0;
-
- foreach (Geography child in children)
- {
- count++;
- count += InitDatabaseThreadCountGeographyChildren (child.Children);
- }
-
- return count;
- }
-
- private static void InitDatabaseThreadCreateGeographyChildren (Geography[] children,
- int parentGeographyId,
- ref Dictionary geographyIdTranslation, string countryCode, ref int count, int total)
- {
- count++;
-
- foreach (Geography geography in children)
- {
- int newGeographyId = SwarmDb.GetDatabaseForWriting().CreateGeography (geography.Name, parentGeographyId);
- geographyIdTranslation[geography.GeographyId] = newGeographyId;
-
- InitDatabaseThreadCreateGeographyChildren (geography.Children, newGeographyId, ref geographyIdTranslation,
- countryCode, ref count, total);
- }
-
- if (total != 0)
- {
- _initMessage = String.Format ("Setting up geography for {0}... ({1}%)", countryCode, count*100/total);
- // shouldn't be here but wtf
- }
- Thread.Sleep (50);
- }
-
[WebMethod]
public static int GetInitProgress()
@@ -692,7 +500,7 @@ public partial class Pages_v5_Init_Default : Page
[WebMethod]
public static string GetInitProgressMessage()
{
- return _initMessage;
+ return _initMessage + GuidCache.Get ("DbInitProgress");
}
[WebMethod]
diff --git a/Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs b/Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs
index 52911dcc..dccd0aa7 100644
--- a/Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs
+++ b/Site5/Pages/v5/Security/SetCurrentOrganization.aspx.cs
@@ -48,6 +48,8 @@ namespace Swarmops.Frontend.Pages.v5.Security
suggestedOrganization.Identity.ToString (CultureInfo.InvariantCulture) + ",," +
logonFlags;
+ CurrentUser.LastLogonOrganizationId = suggestedOrganization.Identity;
+
if (!string.IsNullOrEmpty (returnUrlString))
{
FormsAuthentication.SetAuthCookie (userIdentityString, true);
diff --git a/Site5/Security/FinalizeLogin.aspx.cs b/Site5/Security/FinalizeLogin.aspx.cs
index 6530774a..2cab37ac 100644
--- a/Site5/Security/FinalizeLogin.aspx.cs
+++ b/Site5/Security/FinalizeLogin.aspx.cs
@@ -14,12 +14,13 @@ namespace Swarmops.Security
if (string.IsNullOrEmpty (identity))
{
- Response.Redirect ("Login.aspx");
+ Response.Redirect ("Login");
}
else
{
GuidCache.Delete (nonce + "-Identity");
- FormsAuthentication.RedirectFromLoginPage (identity, true);
+ FormsAuthentication.SetAuthCookie (identity, true);
+ Response.Redirect ("/");
}
}
}
diff --git a/Site5/Security/Images/iconshock-cross-12px.png b/Site5/Security/Images/iconshock-cross-12px.png
new file mode 100644
index 00000000..5c908077
Binary files /dev/null and b/Site5/Security/Images/iconshock-cross-12px.png differ
diff --git a/Site5/Security/Images/iconshock-greentick-16px.png b/Site5/Security/Images/iconshock-greentick-16px.png
new file mode 100644
index 00000000..673f61b0
Binary files /dev/null and b/Site5/Security/Images/iconshock-greentick-16px.png differ
diff --git a/Site5/Security/Login.aspx b/Site5/Security/Login.aspx
index 3a9597c3..a23b417a 100644
--- a/Site5/Security/Login.aspx
+++ b/Site5/Security/Login.aspx
@@ -56,6 +56,7 @@
function onInputCredentials() {
clearTimeout(manualCredentialsTestTrigger);
+ $('#TextLogin, #TextPass').css('background-image', 'none');
manualCredentialsTestTrigger = setTimeout(function() {
testManualCredentials();
@@ -71,6 +72,10 @@
jsonData.credentials2FA = $('#Text2FA').val();
jsonData.logonUriEncoded = bitIdUri;
+ if (jsonData.credentialsLogin.length == 0 || jsonData.credentialsPass.length == 0) {
+ return; // empty pass or login
+ }
+
$.ajax({
type: "POST",
url: "Login.aspx/TestCredentials",
@@ -78,11 +83,15 @@
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
- if (msg.d) {
- // alert(""); // Modal on Chrome, so need a shaded div instead
- } else {
- // do nothing
- }
+ if (msg.d == "Success") {
+ // Good credentials. TODO: Add manual 2FA challenge if applicable.
+ $('#TextLogin, #TextPass').css('background-image', "url('/Security/Images/iconshock-greentick-16px.png')").css('background-position', 'right center').css('background-repeat', 'no-repeat');
+ } else if (msg.d == "Fail") {
+ // inform user of bad credentials by means of a red cross on _both_ boxes
+ $('#TextLogin, #TextPass').css('background-image', "url('/Security/Images/iconshock-cross-12px.png')").css('background-position', 'right center').css('background-repeat', 'no-repeat');
+ } else {
+ // wut?
+ }
},
error: function(msg) {
// retry after a second
@@ -109,7 +118,7 @@
success: function(msg) {
if (msg.d) {
// Login confirmed, fetch auth cookie from nonce in-context
- document.location = "/Security/FinalizeLogin.aspx?Nonce=" + bitIdNonce;
+ document.location = "/Security/FinalizeLogin?Nonce=" + bitIdNonce;
} else {
// Retry twice per second
setTimeout(function() {
diff --git a/Site5/Security/Login.aspx.cs b/Site5/Security/Login.aspx.cs
index 660ba560..27855962 100644
--- a/Site5/Security/Login.aspx.cs
+++ b/Site5/Security/Login.aspx.cs
@@ -12,6 +12,7 @@ using Resources;
using Swarmops.Database;
using Swarmops.Logic.Cache;
using Swarmops.Logic.Security;
+using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
@@ -27,7 +28,7 @@ namespace Swarmops.Pages.Security
if (!SwarmDb.Configuration.IsConfigured())
{
- Response.Redirect ("/Pages/v5/Init/", true);
+ Response.Redirect ("/Init/", true);
return;
}
@@ -77,7 +78,8 @@ namespace Swarmops.Pages.Security
Response.AppendCookie (new HttpCookie ("DashboardMessage",
HttpUtility.UrlEncode (
"You have been logged on as Sandbox Administrator to the Swarmops Development Sandbox.
This machine runs the latest development build, so you may run into diagnostic code and half-finished features. All data here is bogus test data and is reset every night.
In other words, welcome, and play away!
")));
- FormsAuthentication.RedirectFromLoginPage ("1,1", true);
+ FormsAuthentication.SetAuthCookie ("1,1", true);
+ Response.Redirect ("/");
}
// Check for SSL and force it
@@ -234,7 +236,7 @@ namespace Swarmops.Pages.Security
[WebMethod]
// ReSharper disable once InconsistentNaming
- public static bool TestCredentials (string credentialsLogin, string credentialsPass, string credentials2FA,
+ public static string TestCredentials (string credentialsLogin, string credentialsPass, string credentials2FA,
string logonUriEncoded)
{
if (!string.IsNullOrEmpty (credentialsLogin.Trim()) && !string.IsNullOrEmpty (credentialsPass.Trim()))
@@ -248,17 +250,32 @@ namespace Swarmops.Pages.Security
// TODO: Determine last logged-on organization. Right now, log on to Sandbox.
+ int lastOrgId = authenticatedPerson.LastLogonOrganizationId;
+
+ if (lastOrgId == 0)
+ {
+ lastOrgId = Organization.SandboxIdentity;
+ }
+
+ if (!authenticatedPerson.MemberOfWithInherited (lastOrgId))
+ {
+ // If the person doesn't have access to the last organization (anymore), log on to Sandbox
+
+ lastOrgId = 1;
+ }
+
GuidCache.Set (logonUri + "-LoggedOn",
- authenticatedPerson.Identity.ToString (CultureInfo.InvariantCulture) + ",1,,AuthPlain");
- return true;
+ authenticatedPerson.Identity.ToString (CultureInfo.InvariantCulture) + "," + lastOrgId.ToString(CultureInfo.InvariantCulture) + ",,AuthPlain");
+
+ return "Success"; // Prepare here for "2FARequired" return code
}
catch (UnauthorizedAccessException)
{
- return false;
+ return "Fail";
}
}
- return false;
+ return "Fail";
}
@@ -281,7 +298,6 @@ namespace Swarmops.Pages.Security
this.LiteralCredentialsUser.Text = Resources.Pages.Security.Login_Username;
this.LiteralCredentialsPass.Text = Resources.Pages.Security.Login_Password;
this.LiteralCredentials2FA.Text = Resources.Pages.Security.Login_GoogleAuthenticatorCode;
- this.LiteralLoginSuccess.Text = Resources.Pages.Security.Login_LoggingIn;
}
diff --git a/Site5/Style/style-v5.css b/Site5/Style/style-v5.css
index 30fa9d6b..d11aa10d 100644
--- a/Site5/Style/style-v5.css
+++ b/Site5/Style/style-v5.css
@@ -358,6 +358,12 @@ div.loginbox
background-color: #E4ECFF;
}
+
+input.InputManualCredentials {
+ border: solid 1px #A2BEFF;
+ padding: 2px;
+}
+
span.loginalphabetasign
{
font-size: 24px;
diff --git a/Site5/Style/v5-easyui-elements.css b/Site5/Style/v5-easyui-elements.css
index df0a65d0..710194d7 100644
--- a/Site5/Style/v5-easyui-elements.css
+++ b/Site5/Style/v5-easyui-elements.css
@@ -38,6 +38,16 @@
.content h2 span span.combo {
padding-left: 4px !important;
+ padding-top: 0;
+ border: 1px solid #cccccc;
+ border-radius: 4px;
+ box-shadow: 0 0 3px 0 #dddddd inset;
+ cursor: default;
+}
+
+.content h2 span span.combo:hover {
+ border: 1px solid #aaaaaa;
+ box-shadow: 0 0 3px 0 #bbbbbb inset;
}
.content > h2 > span > span.combo > input.combo-text {
diff --git a/Site5/web.config b/Site5/web.config
index 3e81f77d..8aa9a6ca 100644
--- a/Site5/web.config
+++ b/Site5/web.config
@@ -19,7 +19,7 @@
-
+
@@ -42,6 +42,7 @@
+
@@ -53,18 +54,5 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file