diff --git a/Database/Database-Initialization.cs b/Database/Database-Initialization.cs index 9ddf2d4a..0c334a1f 100644 --- a/Database/Database-Initialization.cs +++ b/Database/Database-Initialization.cs @@ -10,7 +10,7 @@ namespace Activizr.Database { partial class PirateDb { - // This function is bloody dangerous, mmkay? + // These functions are bloody dangerous, mmmkay? public void ExecuteAdminCommand(string sqlSequence) { @@ -26,5 +26,28 @@ namespace Activizr.Database command.ExecuteNonQuery(); } } + + public int ExecuteAdminCommandScalar (string sqlSequence) + { + // TODO: Verify that we're in admin mode + + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand(sqlSequence, connection); + command.CommandType = CommandType.Text; + + object result = command.ExecuteScalar(); + + if (result == DBNull.Value) + { + return 0; + } + + return Convert.ToInt32(result); + } + } + } } \ No newline at end of file diff --git a/Logic/Pirates/Person.cs b/Logic/Pirates/Person.cs index df7ac421..10f8ec7f 100644 --- a/Logic/Pirates/Person.cs +++ b/Logic/Pirates/Person.cs @@ -111,6 +111,13 @@ namespace Activizr.Logic.Pirates protected int ResolveGeography () { + if (base.CountryId == 0) + { + base.GeographyId = 1; + PirateDb.GetDatabaseForWriting().SetPersonGeography(this.Identity, 1); + return 1; // root geography, if no country set + } + Structure.Cities cities = Cities.FromPostalCode(this.PostalCode, base.CountryId); City city = null; @@ -137,6 +144,7 @@ namespace Activizr.Logic.Pirates } base.GeographyId = city.GeographyId; + PirateDb.GetDatabaseForWriting().SetPersonGeography(this.Identity, base.GeographyId); return city.GeographyId; } @@ -147,7 +155,7 @@ namespace Activizr.Logic.Pirates { if (GeographyId == 0) { - PirateDb.GetDatabaseForWriting().SetPersonGeography (this.Identity, ResolveGeography()); + ResolveGeography(); } return Geography.FromIdentity(GeographyId); @@ -165,7 +173,7 @@ namespace Activizr.Logic.Pirates { if (base.GeographyId == 0) { - PirateDb.GetDatabaseForWriting().SetPersonGeography(this.Identity, ResolveGeography()); + ResolveGeography(); } return base.GeographyId; @@ -494,7 +502,12 @@ namespace Activizr.Logic.Pirates string postal, string city, string countryCode, DateTime dateOfBirth, PersonGender gender) { - BasicCountry country = PirateDb.GetDatabaseForReading().GetCountry(countryCode); + BasicCountry country = null; + + if (countryCode.Length > 0) + { + country = PirateDb.GetDatabaseForReading().GetCountry(countryCode); + } // Clean data @@ -509,7 +522,7 @@ namespace Activizr.Logic.Pirates postal = postal.Replace(" ", "").Trim(); int personId = PirateDb.GetDatabaseForWriting().CreatePerson(name, email, phone, street, postal, city, - country.Identity, dateOfBirth, gender); + country == null? 0: country.Identity, dateOfBirth, gender); // Resolve the geography diff --git a/Site5/App_GlobalResources/Pages.Init.resx b/Site5/App_GlobalResources/Pages.Init.resx index 80c85ba4..bb219415 100644 --- a/Site5/App_GlobalResources/Pages.Init.resx +++ b/Site5/App_GlobalResources/Pages.Init.resx @@ -121,7 +121,7 @@ No other actions are available until setup is completed. - Welcome to Activizr! This is what the interface looks like, but it's not active yet - first, we'll go through some steps to set up your installation. You'll be up and running in about three minutes. + Welcome to Activizr! This is what the interface looks like, but it's not active yet - first, we'll go through some steps to set up your installation. You'll be up and running shortly. Info box on database setup screen diff --git a/Site5/Images/Abstract/activizr-progressbar-animation.gif b/Site5/Images/Abstract/activizr-progressbar-animation.gif index 1a6648d5..06e7449a 100644 Binary files a/Site5/Images/Abstract/activizr-progressbar-animation.gif and b/Site5/Images/Abstract/activizr-progressbar-animation.gif differ diff --git a/Site5/Pages/v5/Init/Default.aspx b/Site5/Pages/v5/Init/Default.aspx index ac201b11..337b42e0 100644 --- a/Site5/Pages/v5/Init/Default.aspx +++ b/Site5/Pages/v5/Init/Default.aspx @@ -40,13 +40,17 @@ $(document).ready(function () { // Initialize Smart Wizard - $('#wizard').smartWizard({ transitionEffect: 'fade', onLeaveStep: leaveAStepCallback }); + $('#wizard').smartWizard({ transitionEffect: 'fade', onLeaveStep: leaveAStepCallback, onFinish: onFinishCallback }); function leaveAStepCallback(obj) { var stepNum = obj.attr('rel'); return validateStep(stepNum); } + function onFinishCallback(obj) { + $('#<%=this.ButtonLogin.ClientID %>').click(); + } + function validateStep(stepNumber) { var isValid = false; var textBoxes; @@ -62,7 +66,7 @@ $.ajax({ type: "POST", url: "Default.aspx/VerifyHostNameAndAddress", - data: "{'name': '" + hostName + "', 'address': '" + hostAddress + "'}", // TODO: injection vulnerability - strip single quotes from input + data: "{'name': '" + escape(hostName) + "', 'address': '" + escape(hostAddress) + "'}", contentType: "application/json; charset=utf-8", dataType: "json", async: false, // blocks until function returns - race conditions otherwise @@ -166,14 +170,12 @@ } // If all is valid, create the first user. - // TODO: this WILL fuck up when somebody enters O'Hara as name, or anything else containing a single quote. Protect against that. - // TODO: make this throw server-side if there is already a Person.FromIdentity(1). if (isValid) { $.ajax({ type: "POST", url: "Default.aspx/CreateFirstUser", - data: "{'name': '" + $('#<%=this.TextFirstUserName.ClientID %>').val() + "', 'mail': '" + $('#<%=this.TextFirstUserMail.ClientID %>').val() + "', 'address': '" + $('#<%=this.TextFirstUserPassword1.ClientID %>').val() + "'}", // TODO: injection vulnerability - strip single quotes from input + data: "{'name': '" + escape($('#<%=this.TextFirstUserName.ClientID %>').val()) + "', 'mail': '" + escape($('#<%=this.TextFirstUserMail.ClientID %>').val()) + "', 'password': '" + escape($('#<%=this.TextFirstUserPassword1.ClientID %>').val()) + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { @@ -186,7 +188,6 @@ // If we get here, we're always good isValid = true; - // TODO: Click the magic button that logs the first user in } return isValid; @@ -534,50 +535,31 @@

Initializing...