diff --git a/src/MyWebLog.Data/MyWebLog.Data.fsproj b/src/MyWebLog.Data/MyWebLog.Data.fsproj index 3ceef8f..6d6fe1a 100644 --- a/src/MyWebLog.Data/MyWebLog.Data.fsproj +++ b/src/MyWebLog.Data/MyWebLog.Data.fsproj @@ -14,7 +14,7 @@ - + diff --git a/src/MyWebLog/Handlers.fs b/src/MyWebLog/Handlers.fs index 3822884..b9b28a2 100644 --- a/src/MyWebLog/Handlers.fs +++ b/src/MyWebLog/Handlers.fs @@ -98,6 +98,8 @@ module private Helpers = hash.Add ("current_page", ctx.Request.Path.Value.Substring 1) hash.Add ("messages", messages) + do! ctx.Session.CommitAsync () + // NOTE: DotLiquid does not support {% render %} or {% include %} in its templates, so we will do a two-pass // render; the net effect is a "layout" capability similar to Razor or Pug @@ -107,6 +109,7 @@ module private Helpers = // ...then render that content with its layout let! layoutTemplate = TemplateCache.get theme "layout" + return! htmlString (layoutTemplate.Render hash) next ctx } @@ -115,6 +118,12 @@ module private Helpers = return! viewForTheme (deriveWebLogFromHash hash ctx).themePath template next ctx hash } + /// Redirect after doing some action; commits session and issues a temporary redirect + let redirectToGet url : HttpHandler = fun next ctx -> task { + do! ctx.Session.CommitAsync () + return! redirectTo false url next ctx + } + /// Get the web log ID for the current request let webLogId ctx = (WebLogCache.get ctx).id @@ -233,7 +242,7 @@ module Admin = WebLogCache.set ctx updated do! addMessage ctx { UserMessage.success with message = "Web log settings saved successfully" } - return! redirectTo false "/admin" next ctx + return! redirectToGet "/admin" next ctx | None -> return! Error.notFound next ctx } @@ -318,7 +327,7 @@ module Page = do! (match model.pageId with "new" -> Data.Page.add | _ -> Data.Page.update) page conn if updateList then do! PageListCache.update ctx do! addMessage ctx { UserMessage.success with message = "Page saved successfully" } - return! redirectTo false $"/page/{PageId.toString page.id}/edit" next ctx + return! redirectToGet $"/page/{PageId.toString page.id}/edit" next ctx | None -> return! Error.notFound next ctx } @@ -428,7 +437,7 @@ module User = message = "Logged on successfully" detail = Some $"Welcome to {webLog.name}!" } - return! redirectTo false "/admin" next ctx + return! redirectToGet "/admin" next ctx | _ -> do! addMessage ctx { UserMessage.error with message = "Log on attempt unsuccessful" } return! logOn next ctx @@ -438,7 +447,7 @@ module User = let logOff : HttpHandler = fun next ctx -> task { do! ctx.SignOutAsync CookieAuthenticationDefaults.AuthenticationScheme do! addMessage ctx { UserMessage.info with message = "Log off successful" } - return! redirectTo false "/" next ctx + return! redirectToGet "/" next ctx } diff --git a/src/MyWebLog/MyWebLog.fsproj b/src/MyWebLog/MyWebLog.fsproj index 2d45c30..34c3db5 100644 --- a/src/MyWebLog/MyWebLog.fsproj +++ b/src/MyWebLog/MyWebLog.fsproj @@ -16,7 +16,7 @@ - + diff --git a/src/MyWebLog/Program.fs b/src/MyWebLog/Program.fs index 25cfcdf..067ba9a 100644 --- a/src/MyWebLog/Program.fs +++ b/src/MyWebLog/Program.fs @@ -164,7 +164,6 @@ let main args = let _ = builder.Services.AddLogging () let _ = builder.Services.AddAuthorization () let _ = builder.Services.AddAntiforgery () - let _ = builder.Services.AddGiraffe () // Configure RethinkDB's connection JsonConverters.all () |> Seq.iter Converter.Serializer.Converters.Add @@ -180,14 +179,17 @@ let main args = } |> Async.AwaitTask |> Async.RunSynchronously let _ = builder.Services.AddSingleton conn - let _ = builder.Services.AddDistributedRethinkDBCache (fun opts -> - opts.Database <- rethinkCfg.Database - opts.Connection <- conn) +// let _ = builder.Services.AddDistributedRethinkDBCache (fun opts -> +// opts.Connection <- conn) + let _ = builder.Services.AddDistributedMemoryCache () let _ = builder.Services.AddSession(fun opts -> opts.IdleTimeout <- TimeSpan.FromMinutes 30 opts.Cookie.HttpOnly <- true opts.Cookie.IsEssential <- true) + // this needs to be after the session... maybe? + let _ = builder.Services.AddGiraffe () + // Set up DotLiquid Template.RegisterFilter typeof Template.RegisterTag "user_links" diff --git a/src/MyWebLog/themes/admin/page-list.liquid b/src/MyWebLog/themes/admin/page-list.liquid index 474fac4..2ffe06e 100644 --- a/src/MyWebLog/themes/admin/page-list.liquid +++ b/src/MyWebLog/themes/admin/page-list.liquid @@ -1,24 +1,28 @@

{{ page_title }}

- Create a New Page - + Create a New Page +
- - {% for pg in pages -%} - - {%- endfor %} diff --git a/src/MyWebLog/themes/admin/post-list.liquid b/src/MyWebLog/themes/admin/post-list.liquid new file mode 100644 index 0000000..e69de29
Actions TitleIn List? Last Updated
Edit {{ pg.title }} {%- if pg.is_default %}   HOME PAGE{% endif -%} + {%- if pg.show_in_page_list %}   IN PAGE LIST {% endif -%}
+ + View Page + + Edit Page + + Delete Page +
{% if pg.show_in_page_list %} Yes {% else %} No {% endif %} {{ pg.updated_on | date: "MMMM d, yyyy" }}