Fixes the anonymous profile usage

* NpgsqlMembershipProvider.cs: insert a profile record before
  inserting the users record,
to ensure a new foreign key constraint

* NpgsqlProfileProvider.cs: better comments

* 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

* LocalizedText.resx:
* LocalizedText.fr.resx:
* LocalizedText.Designer.cs:
* LocalizedText.fr.Designer.cs: I understood ...

* Notification.cs: a new click action name.

* instdbws.sql: permits profile records with no users record
  associated to,
and so, anonymous profiles creation.
main
Paul Schneider 10 years ago
parent e6c65019b0
commit cbb596ca04
17 changed files with 104 additions and 46 deletions

@ -1,3 +1,11 @@
2015-11-03 Paul Schneider <paul@pschneider.fr>
* 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 <paul@pschneider.fr>
* NpgsqlMembershipProvider.cs: xmldoc

@ -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;

@ -193,13 +193,14 @@ namespace Npgsql.Web
/// <param name="context">Context.</param>
/// <param name="collection">Collection.</param>
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,7 +229,6 @@ namespace Npgsql.Web
}
}
return c;
}
private object GetDefaultValue(SettingsProperty setting)
@ -236,7 +236,6 @@ namespace Npgsql.Web
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

@ -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 ();
}
}

@ -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 (

@ -1,3 +1,23 @@
2015-11-03 Paul Schneider <paul@pschneider.fr>
* 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 <paul@pschneider.fr>
* CalAuth.aspx: A view ... still unused

@ -24,21 +24,6 @@ namespace Yavsc.Controllers
/// </summary>
public class HomeController : Controller
{
// Site name
private static string name = null;
/// <summary>
/// Gets or sets the site name.
/// </summary>
/// <value>The name.</value>
[Obsolete("Use YavscHelpers.SiteName insteed.")]
public static string Name {
get {
if (name == null)
name = WebConfigurationManager.AppSettings ["Name"];
return name;
}
}
/// <summary>
/// Lists the referenced assemblies.
@ -87,16 +72,15 @@ namespace Yavsc.Controllers
/// </summary>
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")
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:'"+anonid+"' });}");
}
"function(){Yavsc.ajax(\"/Yavsc/AllowCookies\", { id:'"+uid+"' });}",
LocalizedText.I_understood);
}
foreach (string tagname in new string[] {"Accueil","Événements","Mentions légales"})

@ -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<Notification> ();
(ViewData ["Notifications"] as List<Notification>).Add (
new Notification { body = YavscAjaxHelper.QuoteJavascriptString(message),
click_action = click_action } ) ;
note ) ;
}
/// <summary>
/// Files the list.

@ -41,7 +41,7 @@ var apiBaseUrl = '<%=Url.Content(Yavsc.WebApiConfig.UrlPrefixRelative)%>';
$(document).ready(function(){
<% foreach (Notification note in (IEnumerable<Notification>) 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%>); <% } %>
<% } %>
});
</script>

@ -179,11 +179,12 @@ http://msdn2.microsoft.com/en-us/library/b5ysx397.aspx
<providerOption name="CompilerVersion" value="v4.0" />
<providerOption name="WarnAsError" value="false" />
</compiler>
<!--
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" warningLevel="4" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<providerOption name="CompilerVersion" value="v4.0" />
<providerOption name="OptionInfer" value="true" />
<providerOption name="WarnAsError" value="false" />
</compiler>
</compiler> -->
</compilers>
</system.codedom>
<!-- <system.web.extensions>

@ -143,6 +143,7 @@
<Folder Include="App_Data\" />
<Folder Include="App_Themes\images\" />
<Folder Include="Views\Google\" />
<Folder Include="App_Data\Sql\" />
</ItemGroup>
<ItemGroup>
<Compile Include="Controllers\HomeController.cs" />
@ -533,7 +534,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="App_Data\instdbws.sql" />
<EmbeddedResource Include="App_Data\Sql\instdbws.sql" />
</ItemGroup>
<ItemGroup>
<WebReferences Include="Web References" />

@ -1,3 +1,12 @@
2015-11-03 Paul Schneider <paul@pschneider.fr>
* LocalizedText.resx:
* LocalizedText.fr.resx:
* LocalizedText.Designer.cs:
* LocalizedText.fr.Designer.cs: I understood ...
* Notification.cs: a new click action name.
2015-11-01 Paul Schneider <paul@pschneider.fr>
* YavscModel.csproj:

@ -304,6 +304,12 @@ namespace Yavsc.Model {
}
}
public static string I_understood {
get {
return ResourceManager.GetString("I_understood", resourceCulture);
}
}
public static string Bill_removal {
get {
return ResourceManager.GetString("Bill_removal", resourceCulture);

@ -298,6 +298,12 @@ namespace Yavsc.Model {
}
}
public static string I_understood {
get {
return ResourceManager.GetString("I_understood", resourceCulture);
}
}
public static string Bill_removal {
get {
return ResourceManager.GetString("Bill_removal", resourceCulture);

@ -42,6 +42,7 @@
<data name="Hide_source"><value>Cacher le texte source du billet</value></data>
<data name="Home"><value>Accueil</value></data>
<data name="Hide"><value>Cacher</value></data>
<data name="I_understood"><value>J'ai compris</value></data>
<data name="ImgLocator"><value>URI de l'image</value></data>
<data name="ImportException"><value>Exception à l'import</value></data>
<data name="InternalServerError"><value>Erreur serveur interne</value></data>

@ -43,6 +43,7 @@
<data name="entries"><value>entries</value></data>
<data name="Google_calendar"><value>Google calendar</value></data>
<data name="Google_error"><value>Google error : {0}</value></data>
<data name="I_understood"><value>I understood</value></data>
<data name="InternalServerError"><value>Internal Server Error</value></data>
<data name="ImgLocator"><value>Image URI</value></data>
<data name="ImportException"><value>Exception at importing</value></data>

@ -27,6 +27,8 @@ namespace Yavsc.Model.Messaging
public Notification ()
{
}
public string click_action_name ;
}
}

Loading…