So close...
- Added comment display and counts - Fixed problem with set-up-from-scratch bombing on index creation - RSS feed is returning errors; need to determine why Nginx is intercepting theme content requests
This commit is contained in:
@@ -112,7 +112,7 @@ type MyWebLogBootstrapper() =
|
||||
CryptographyConfiguration (
|
||||
AesEncryptionProvider (PassphraseKeyGenerator (cfg.AuthEncryptionPassphrase, cfg.AuthSalt)),
|
||||
DefaultHmacProvider (PassphraseKeyGenerator (cfg.AuthHmacPassphrase, cfg.AuthSalt))),
|
||||
RedirectUrl = "~/user/logon",
|
||||
RedirectUrl = "~/user/log-on",
|
||||
UserMapper = container.Resolve<IUserMapper> ())
|
||||
FormsAuthentication.Enable (pipelines, auth)
|
||||
// CSRF
|
||||
@@ -163,6 +163,7 @@ let Run () =
|
||||
use host =
|
||||
WebHostBuilder()
|
||||
.UseContentRoot(System.IO.Directory.GetCurrentDirectory ())
|
||||
.UseUrls("http://localhost:5001")
|
||||
.UseKestrel()
|
||||
.UseStartup<Startup>()
|
||||
.Build ()
|
||||
|
||||
@@ -14,10 +14,10 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
inherit NancyModule ()
|
||||
|
||||
do
|
||||
this.Get ("/categories", fun _ -> this.CategoryList ())
|
||||
this.Get ("/category/{id}/edit", fun parms -> this.EditCategory (downcast parms))
|
||||
this.Post ("/category/{id}/edit", fun parms -> this.SaveCategory (downcast parms))
|
||||
this.Delete ("/category/{id}/delete", fun parms -> this.DeleteCategory (downcast parms))
|
||||
this.Get ("/categories", fun _ -> this.CategoryList ())
|
||||
this.Get ("/category/{id}/edit", fun p -> this.EditCategory (downcast p))
|
||||
this.Post ("/category/{id}/edit", fun p -> this.SaveCategory (downcast p))
|
||||
this.Post ("/category/{id}/delete", fun p -> this.DeleteCategory (downcast p))
|
||||
|
||||
/// Display a list of categories
|
||||
member this.CategoryList () : obj =
|
||||
@@ -26,6 +26,7 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
CategoryListModel (
|
||||
this.Context, this.WebLog, findAllCategories data this.WebLog.Id
|
||||
|> List.map (fun cat -> IndentedCategory.Create cat (fun _ -> false)))
|
||||
model.PageTitle <- Strings.get "Categories"
|
||||
upcast this.View.["admin/category/list", model]
|
||||
|
||||
/// Edit a category
|
||||
@@ -35,10 +36,11 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
match catId with "new" -> Some Category.Empty | _ -> tryFindCategory data this.WebLog.Id catId
|
||||
|> function
|
||||
| Some cat ->
|
||||
let model = CategoryEditModel(this.Context, this.WebLog, cat)
|
||||
let model = CategoryEditModel (this.Context, this.WebLog, cat)
|
||||
model.Categories <- findAllCategories data this.WebLog.Id
|
||||
|> List.map (fun cat -> IndentedCategory.Create cat
|
||||
(fun c -> c = defaultArg (fst cat).ParentId ""))
|
||||
|> List.map (fun c ->
|
||||
IndentedCategory.Create c (fun catId -> catId = defaultArg cat.ParentId ""))
|
||||
model.PageTitle <- Strings.get <| match catId with "new" -> "AddNewCategory" | _ -> "EditCategory"
|
||||
upcast this.View.["admin/category/edit", model]
|
||||
| _ -> this.NotFound ()
|
||||
|
||||
@@ -53,10 +55,13 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
| _ -> tryFindCategory data this.WebLog.Id catId
|
||||
|> function
|
||||
| Some old ->
|
||||
let cat = { old with Name = form.Name
|
||||
Slug = form.Slug
|
||||
Description = match form.Description with "" -> None | d -> Some d
|
||||
ParentId = match form.ParentId with "" -> None | p -> Some p }
|
||||
let cat =
|
||||
{ old with
|
||||
Name = form.Name
|
||||
Slug = form.Slug
|
||||
Description = match form.Description with "" -> None | d -> Some d
|
||||
ParentId = match form.ParentId with "" -> None | p -> Some p
|
||||
}
|
||||
let newCatId = saveCategory data cat
|
||||
match old.ParentId = cat.ParentId with
|
||||
| true -> ()
|
||||
@@ -68,12 +73,12 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
| Some parentId -> addCategoryToParent data this.WebLog.Id parentId newCatId
|
||||
| _ -> ()
|
||||
let model = MyWebLogModel (this.Context, this.WebLog)
|
||||
{ UserMessage.Empty with
|
||||
Level = Level.Info
|
||||
Message = System.String.Format
|
||||
(Strings.get "MsgCategoryEditSuccess",
|
||||
Strings.get (match catId with "new" -> "Added" | _ -> "Updated")) }
|
||||
|> model.AddMessage
|
||||
model.AddMessage
|
||||
{ UserMessage.Empty with
|
||||
Message = System.String.Format
|
||||
(Strings.get "MsgCategoryEditSuccess",
|
||||
Strings.get (match catId with "new" -> "Added" | _ -> "Updated"))
|
||||
}
|
||||
this.Redirect (sprintf "/category/%s/edit" newCatId) model
|
||||
| _ -> this.NotFound ()
|
||||
|
||||
@@ -85,10 +90,8 @@ type CategoryModule (data : IMyWebLogData) as this =
|
||||
match tryFindCategory data this.WebLog.Id catId with
|
||||
| Some cat ->
|
||||
deleteCategory data cat
|
||||
let model = MyWebLogModel(this.Context, this.WebLog)
|
||||
{ UserMessage.Empty with
|
||||
Level = Level.Info
|
||||
Message = System.String.Format(Strings.get "MsgCategoryDeleted", cat.Name) }
|
||||
|> model.AddMessage
|
||||
let model = MyWebLogModel (this.Context, this.WebLog)
|
||||
model.AddMessage
|
||||
{ UserMessage.Empty with Message = System.String.Format(Strings.get "MsgCategoryDeleted", cat.Name) }
|
||||
this.Redirect "/categories" model
|
||||
| _ -> this.NotFound ()
|
||||
|
||||
@@ -23,16 +23,17 @@ type UserModule (data : IMyWebLogData, cfg : AppConfig) as this =
|
||||
|> Seq.fold (fun acc byt -> sprintf "%s%s" acc (byt.ToString "x2")) ""
|
||||
|
||||
do
|
||||
this.Get ("/logon", fun _ -> this.ShowLogOn ())
|
||||
this.Post ("/logon", fun p -> this.DoLogOn (downcast p))
|
||||
this.Get ("/logoff", fun _ -> this.LogOff ())
|
||||
this.Get ("/log-on", fun _ -> this.ShowLogOn ())
|
||||
this.Post ("/log-on", fun p -> this.DoLogOn (downcast p))
|
||||
this.Get ("/log-off", fun _ -> this.LogOff ())
|
||||
|
||||
/// Show the log on page
|
||||
member this.ShowLogOn () : obj =
|
||||
let model = LogOnModel (this.Context, this.WebLog)
|
||||
let query = this.Request.Query :?> DynamicDictionary
|
||||
model.Form.ReturnUrl <- match query.ContainsKey "returnUrl" with true -> query.["returnUrl"].ToString () | _ -> ""
|
||||
upcast this.View.["admin/user/logon", model]
|
||||
model.PageTitle <- Strings.get "LogOn"
|
||||
upcast this.View.["admin/user/log-on", model]
|
||||
|
||||
/// Process a user log on
|
||||
member this.DoLogOn (parameters : DynamicDictionary) : obj =
|
||||
@@ -52,12 +53,10 @@ type UserModule (data : IMyWebLogData, cfg : AppConfig) as this =
|
||||
Level = Level.Error
|
||||
Message = Strings.get "ErrBadLogOnAttempt" }
|
||||
|> model.AddMessage
|
||||
this.Redirect (sprintf "/user/logon?returnUrl=%s" form.ReturnUrl) model
|
||||
this.Redirect (sprintf "/user/log-on?returnUrl=%s" form.ReturnUrl) model
|
||||
|
||||
/// Log a user off
|
||||
member this.LogOff () : obj =
|
||||
// FIXME: why are we getting the user here if we don't do anything with it?
|
||||
let user = this.Request.PersistableSession.GetOrDefault<User> (Keys.User, User.Empty)
|
||||
this.Session.DeleteAll ()
|
||||
let model = MyWebLogModel (this.Context, this.WebLog)
|
||||
model.AddMessage { UserMessage.Empty with Message = Strings.get "MsgLogOffSuccess" }
|
||||
|
||||
@@ -176,7 +176,7 @@ type IndentedCategory =
|
||||
Selected : bool }
|
||||
with
|
||||
/// Create an indented category
|
||||
static member Create (cat : Category * int) (isSelected : string -> bool) =
|
||||
static member Create cat isSelected =
|
||||
{ Category = fst cat
|
||||
Indent = snd cat
|
||||
Selected = isSelected (fst cat).Id }
|
||||
@@ -304,6 +304,17 @@ type EditPageModel (ctx, webLog, page, revision) =
|
||||
|
||||
// ---- Post models ----
|
||||
|
||||
/// Formatter for comment information
|
||||
type CommentForDisplay (comment : Comment, tz) =
|
||||
/// The comment on which this model is based
|
||||
member this.Comment = comment
|
||||
/// The commentor (linked with a URL if there is one)
|
||||
member this.Commentor =
|
||||
match comment.Url with Some url -> sprintf "<a href=\"%s\">%s</a>" url comment.Name | _ -> comment.Name
|
||||
/// The date/time this comment was posted
|
||||
member this.CommentedOn =
|
||||
sprintf "%s / %s" (FormatDateTime.longDate tz comment.PostedOn) (FormatDateTime.time tz comment.PostedOn)
|
||||
|
||||
/// Model for single post display
|
||||
type PostModel (ctx, webLog, post) =
|
||||
inherit MyWebLogModel (ctx, webLog)
|
||||
@@ -317,8 +328,19 @@ type PostModel (ctx, webLog, post) =
|
||||
member this.PublishedDate = this.DisplayLongDate this.Post.PublishedOn
|
||||
/// The time the post was published
|
||||
member this.PublishedTime = this.DisplayTime this.Post.PublishedOn
|
||||
/// The number of comments
|
||||
member this.CommentCount =
|
||||
match post.Comments |> List.length with
|
||||
| 0 -> Strings.get "NoComments"
|
||||
| 1 -> Strings.get "OneComment"
|
||||
| x -> String.Format (Strings.get "XComments", x)
|
||||
/// The comments for display
|
||||
member this.Comments = post.Comments
|
||||
|> List.filter (fun c -> c.Status = CommentStatus.Approved)
|
||||
|> List.map (fun c -> CommentForDisplay (c, webLog.TimeZone))
|
||||
|
||||
/// Does the post have tags?
|
||||
member this.HasTags = not (List.isEmpty post.Tags)
|
||||
member this.HasTags = not <| List.isEmpty post.Tags
|
||||
/// Get the tags sorted
|
||||
member this.Tags = post.Tags
|
||||
|> List.sort
|
||||
@@ -347,6 +369,12 @@ type PostForDisplay (webLog : WebLog, post : Post) =
|
||||
match this.Post.Status with
|
||||
| PostStatus.Published -> FormatDateTime.time this.TimeZone this.Post.PublishedOn
|
||||
| _ -> FormatDateTime.time this.TimeZone this.Post.UpdatedOn
|
||||
/// The number of comments
|
||||
member this.CommentCount =
|
||||
match post.Comments |> List.length with
|
||||
| 0 -> Strings.get "NoComments"
|
||||
| 1 -> Strings.get "OneComment"
|
||||
| x -> String.Format (Strings.get "XComments", x)
|
||||
/// Tags
|
||||
member this.Tags =
|
||||
match List.length this.Post.Tags with
|
||||
|
||||
Reference in New Issue
Block a user