diff --git a/NpgsqlMRPProviders/ChangeLog b/NpgsqlMRPProviders/ChangeLog index 1dc6a850..f60947f5 100644 --- a/NpgsqlMRPProviders/ChangeLog +++ b/NpgsqlMRPProviders/ChangeLog @@ -1,3 +1,11 @@ +2015-11-03 Paul Schneider + + * NpgsqlMembershipProvider.cs: insert a profile record before + inserting the users record, + to ensure a new foreign key constraint + + * NpgsqlProfileProvider.cs: better comments + 2015-11-01 Paul Schneider * NpgsqlMembershipProvider.cs: xmldoc diff --git a/NpgsqlMRPProviders/NpgsqlMembershipProvider.cs b/NpgsqlMRPProviders/NpgsqlMembershipProvider.cs index 72b9d9d0..88106ced 100644 --- a/NpgsqlMRPProviders/NpgsqlMembershipProvider.cs +++ b/NpgsqlMRPProviders/NpgsqlMembershipProvider.cs @@ -374,6 +374,16 @@ namespace Npgsql.Web } } + using (NpgsqlConnection conn = new NpgsqlConnection (connectionString)) { + using (NpgsqlCommand cmd = new NpgsqlCommand ("INSERT INTO profiles (username,applicationname,isanonymous)\n" + + "VALUES (:uname,:app,FALSE)")) { + cmd.Parameters.AddWithValue ("uname", username); + cmd.Parameters.AddWithValue ("app", pApplicationName); + conn.Open (); + cmd.ExecuteNonQuery (); + } + } + using (NpgsqlConnection conn = new NpgsqlConnection (connectionString)) { using (NpgsqlCommand cmd = new NpgsqlCommand ("INSERT INTO Users " + " (PKID, Username, Passw, Email, PasswordQuestion, " + @@ -406,7 +416,7 @@ namespace Npgsql.Web cmd.Parameters.AddWithValue ("@FailedPasswordAttemptWindowStart", createDate); cmd.Parameters.AddWithValue ("@FailedPasswordAnswerAttemptCount", 0); cmd.Parameters.AddWithValue ("@FailedPasswordAnswerAttemptWindowStart", createDate); - conn.Open (); + int recAdded = cmd.ExecuteNonQuery (); if (recAdded > 0) { status = MembershipCreateStatus.Success; diff --git a/NpgsqlMRPProviders/NpgsqlProfileProvider.cs b/NpgsqlMRPProviders/NpgsqlProfileProvider.cs index 96bc17c3..f8cf83c5 100644 --- a/NpgsqlMRPProviders/NpgsqlProfileProvider.cs +++ b/NpgsqlMRPProviders/NpgsqlProfileProvider.cs @@ -193,13 +193,14 @@ namespace Npgsql.Web /// Context. /// Collection. public override SettingsPropertyValueCollection GetPropertyValues (SettingsContext context, SettingsPropertyCollection collection) - { + {// TODO get anon SettingsPropertyValueCollection c = new SettingsPropertyValueCollection (); if (collection == null || collection.Count < 1 || context == null) return c; - string username = (string)context ["UserName"]; + string username = (string) context ["UserName"]; if (String.IsNullOrEmpty (username)) return c; + using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) using (NpgsqlCommand cmd = cnx.CreateCommand ()) { cmd.CommandText = "SELECT * from profiledata, profiles where " + @@ -228,15 +229,13 @@ namespace Npgsql.Web } } return c; - } private object GetDefaultValue(SettingsProperty setting) { if (setting.PropertyType.IsEnum) return Enum.Parse(setting.PropertyType, setting.DefaultValue.ToString()); - - // Return the default value if it is set + // Return the default value if it is set if (setting.DefaultValue != null) { @@ -259,8 +258,12 @@ namespace Npgsql.Web if (collection == null) return; long puid = 0; - string username = (string)context ["UserName"]; - + string username = (string) context ["UserName"]; + // This user is either a authentified username, or an anonymous asp user id + // He's anonymous when he's got no associated record in the "users" table + // But, as long as our membership provider creates a mandatory (by db constraint) associated + // record in the profile table, with a "isanonymous" field value to FALSE, + // we can asume that an inexistant profile, once here, is an anonymous profile using (NpgsqlConnection cnx = new NpgsqlConnection (connectionString)) { cnx.Open (); using (NpgsqlCommand cmdpi = cnx.CreateCommand ()) { @@ -272,13 +275,12 @@ namespace Npgsql.Web long c = (long)cmdpi.ExecuteScalar (); if (c == 0) { + // the `isanonymous` field is specified true by default cmdpi.CommandText = "insert into profiles (username,applicationname) " + "values ( @username, @appname ) " + "returning uniqueid"; puid = (long)cmdpi.ExecuteScalar (); - // TODO spec: profiledata insertion <=> profile insertion - // => BAD DESIGN - // + using (NpgsqlCommand cmdpdins = cnx.CreateCommand ()) { cmdpdins.CommandText = "insert into profiledata (uniqueid) values (@puid)"; cmdpdins.Parameters.AddWithValue ("@puid", puid); @@ -295,6 +297,7 @@ namespace Npgsql.Web foreach (SettingsPropertyValue s in collection) { if (s.UsingDefaultValue) { //TODO Drop the property in the profile + } else { // update the property value // TODO update to null values (included to avoid Not Implemented columns in profiledata diff --git a/web/ApiControllers/YavscController.cs b/web/ApiControllers/YavscController.cs index ce8c172d..db64f8df 100644 --- a/web/ApiControllers/YavscController.cs +++ b/web/ApiControllers/YavscController.cs @@ -37,8 +37,9 @@ namespace Yavsc.ApiControllers public void AllowCookies (Auth model) { if (model.Id != null) { - ProfileBase anonymousProfile = ProfileBase.Create (model.Id); - anonymousProfile.SetPropertyValue ("allowcookies", true); + ProfileBase pr = ProfileBase.Create (model.Id); + pr.SetPropertyValue ("allowcookies", true); + pr.Save (); } } diff --git a/web/App_Data/instdbws.sql b/web/App_Data/Sql/instdbws.sql similarity index 99% rename from web/App_Data/instdbws.sql rename to web/App_Data/Sql/instdbws.sql index e8a0c2ad..89c514dd 100644 --- a/web/App_Data/instdbws.sql +++ b/web/App_Data/Sql/instdbws.sql @@ -25,6 +25,9 @@ CREATE TABLE users failedpasswordanswerattemptcount integer, failedpasswordanswerattemptwindowstart timestamp with time zone, CONSTRAINT users_pkey PRIMARY KEY (pkid), + CONSTRAINT users_applicationname_fkey FOREIGN KEY (applicationname, username) + REFERENCES profiles (applicationname, username) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT uniquelogin UNIQUE (applicationname, email), CONSTRAINT uniquemail UNIQUE (applicationname, username) ) @@ -82,9 +85,6 @@ CREATE TABLE profiles lastactivitydate timestamp with time zone, lastupdateddate timestamp with time zone, CONSTRAINT profiles_pkey PRIMARY KEY (uniqueid), - CONSTRAINT fk_profileusers FOREIGN KEY (username, applicationname) - REFERENCES users (username, applicationname) MATCH SIMPLE - ON UPDATE CASCADE ON DELETE CASCADE, CONSTRAINT pkprofiles UNIQUE (username, applicationname) ) WITH ( diff --git a/web/ChangeLog b/web/ChangeLog index 3c949cc2..a158a50d 100644 --- a/web/ChangeLog +++ b/web/ChangeLog @@ -1,3 +1,23 @@ +2015-11-03 Paul Schneider + + * YavscController.cs: Fixes the cookies agreement + + * HomeController.cs: Finalizes the cookie agreement system. + + * YavscHelpers.cs: Adds a "click_action_name" field, to give a + text to the notification dimissing button. + + + * App.master: Uses the new field from Notification + + * Web.config: No VB code to compile + + * Web.csproj: moves Sql files to Sql folder + + * instdbws.sql: permits profile records with no users record + associated to, + and so, anonymous profiles creation. + 2015-11-01 Paul Schneider * CalAuth.aspx: A view ... still unused diff --git a/web/Controllers/HomeController.cs b/web/Controllers/HomeController.cs index 9a1d6c9a..80e58123 100644 --- a/web/Controllers/HomeController.cs +++ b/web/Controllers/HomeController.cs @@ -24,21 +24,6 @@ namespace Yavsc.Controllers /// public class HomeController : Controller { - // Site name - private static string name = null; - - /// - /// Gets or sets the site name. - /// - /// The name. - [Obsolete("Use YavscHelpers.SiteName insteed.")] - public static string Name { - get { - if (name == null) - name = WebConfigurationManager.AppSettings ["Name"]; - return name; - } - } /// /// Lists the referenced assemblies. @@ -87,16 +72,15 @@ namespace Yavsc.Controllers /// public ActionResult Index () { - var anonid = Request.AnonymousID; if (Session.IsNewSession) { - if (!Request.IsAuthenticated) { - ProfileBase anonymousProfile = ProfileBase.Create(anonid); - object ac = anonymousProfile.GetPropertyValue ("allowcookies"); - - if (ac is string && ((string)ac)!="true") - YavscHelpers.Notify (ViewData, LocalizedText.ThisSiteUsesCookies, - "function(){Yavsc.ajax(\"/Yavsc/AllowCookies\", { id:'"+anonid+"' });}"); - } + string uid = (!Request.IsAuthenticated) ? Request.AnonymousID : User.Identity.Name; + ProfileBase pr = + ProfileBase.Create (uid); + bool ac = (bool) pr.GetPropertyValue ("allowcookies"); + if (!ac) + YavscHelpers.Notify (ViewData, LocalizedText.ThisSiteUsesCookies, + "function(){Yavsc.ajax(\"/Yavsc/AllowCookies\", { id:'"+uid+"' });}", + LocalizedText.I_understood); } foreach (string tagname in new string[] {"Accueil","Événements","Mentions légales"}) diff --git a/web/Helpers/YavscHelpers.cs b/web/Helpers/YavscHelpers.cs index a0d7abcc..ea00a02b 100644 --- a/web/Helpers/YavscHelpers.cs +++ b/web/Helpers/YavscHelpers.cs @@ -225,12 +225,17 @@ namespace Yavsc.Helpers JavaScriptSerializer serializer = new JavaScriptSerializer(); return serializer.Serialize(obj); } - public static void Notify(ViewDataDictionary ViewData, string message, string click_action=null) { + + public static void Notify(ViewDataDictionary ViewData, string message, string click_action=null, string clickActionName="Ok") { + Notify(ViewData, new Notification { body = YavscAjaxHelper.QuoteJavascriptString(message), + click_action = click_action, click_action_name = YavscAjaxHelper.QuoteJavascriptString(clickActionName)} ) ; + } + + public static void Notify(ViewDataDictionary ViewData, Notification note) { if (ViewData ["Notifications"] == null) ViewData ["Notifications"] = new List (); (ViewData ["Notifications"] as List).Add ( - new Notification { body = YavscAjaxHelper.QuoteJavascriptString(message), - click_action = click_action } ) ; + note ) ; } /// /// Files the list. diff --git a/web/Models/App.master b/web/Models/App.master index ba05644f..0e2e44c2 100644 --- a/web/Models/App.master +++ b/web/Models/App.master @@ -41,7 +41,7 @@ var apiBaseUrl = '<%=Url.Content(Yavsc.WebApiConfig.UrlPrefixRelative)%>'; $(document).ready(function(){ <% foreach (Notification note in (IEnumerable) ViewData ["Notifications"] ) { if (note.click_action == null) {%> Yavsc.notice(<%=note.body%>); <% } -else {%> Yavsc.notice(<%=note.body%>, <%=note.click_action%>); <% } %> +else {%> Yavsc.notice(<%=note.body%>, <%=note.click_action%>, <%=note.click_action_name%>); <% } %> <% } %> }); diff --git a/web/Web.config b/web/Web.config index e254f986..48e58f98 100644 --- a/web/Web.config +++ b/web/Web.config @@ -179,11 +179,12 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx +