2016-07-10 02:11:50 +00:00
|
|
|
[<AutoOpen>]
|
|
|
|
module myWebLog.ModuleExtensions
|
2016-07-09 04:18:44 +00:00
|
|
|
|
2016-07-10 02:11:50 +00:00
|
|
|
open myWebLog
|
2016-07-09 04:18:44 +00:00
|
|
|
open myWebLog.Entities
|
|
|
|
open Nancy
|
|
|
|
open Nancy.Security
|
|
|
|
|
|
|
|
/// Parent class for all myWebLog Nancy modules
|
2016-07-10 02:11:50 +00:00
|
|
|
type NancyModule with
|
2016-07-09 04:18:44 +00:00
|
|
|
|
|
|
|
/// Strongly-typed access to the web log for the current request
|
|
|
|
member this.WebLog = this.Context.Items.[Keys.WebLog] :?> WebLog
|
|
|
|
|
|
|
|
/// Display a view using the theme specified for the web log
|
2016-07-10 02:11:50 +00:00
|
|
|
member this.ThemedView view model = this.View.[(sprintf "%s/%s" this.WebLog.themePath view), model]
|
2016-07-09 04:18:44 +00:00
|
|
|
|
|
|
|
/// Return a 404
|
|
|
|
member this.NotFound () = this.Negotiate.WithStatusCode 404
|
|
|
|
|
2016-07-10 02:11:50 +00:00
|
|
|
/// Redirect a request, storing messages in the session if they exist
|
|
|
|
member this.Redirect url (model : MyWebLogModel) =
|
|
|
|
match List.length model.messages with
|
|
|
|
| 0 -> ()
|
|
|
|
| _ -> this.Session.[Keys.Messages] <- model.messages
|
|
|
|
this.Negotiate.WithHeader("Location", url).WithStatusCode(HttpStatusCode.TemporaryRedirect)
|
|
|
|
|
2016-07-09 04:18:44 +00:00
|
|
|
/// Require a specific level of access for the current web log
|
|
|
|
member this.RequiresAccessLevel level =
|
|
|
|
this.RequiresAuthentication()
|
|
|
|
this.RequiresClaims [| sprintf "%s|%s" this.WebLog.id level |]
|