Hi!

Regarding HTTPS, there is nothing built-in yet, but you can use something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
    let RedirectToHttps (f: Context<'T> -> 'T -> Async<Content<'T>>) =
        fun (ctx: Context<'T>) (ep: 'T) ->
            match ctx.RequestUri.Scheme with
            | "https" -> f ctx ep
            | _ ->
                System.UriBuilder(ctx.RequestUri, 
                    Scheme = "https",
                    Port = (if ctx.RequestUri.IsDefaultPort then -1 else ctx.RequestUri.Port)
                ).ToString()
                |> Content.RedirectPermanentToUrl

// Example use:
    let MySite =
        Application.MultiPage (RedirectToHttps <| fun ctx endpoint ->
            // ...
        )

For user authentication, there is no attribute, but you can factor the authentication management into a reusable function, something like this maybe:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
    let Authorize (f: Context<EndPoint> -> Database.UserData -> Async<Content<EndPoint>>) (ctx: Context<EndPoint>) = async {
        let! loggedIn = ctx.UserSession.GetLoggedInUser()
        match loggedIn |> Option.bind Database.TryGetUser with
        | Some user -> return! f ctx user
        | None -> return! Templating.Main ctx EndPoint.Private "Log in" [NotLoggedInErrorMessage ctx]
    }

    let PrivatePage = Authorize <| fun ctx user -> async {
        let body =
            Templating.MainTemplate.PrivateNotLoggedInContent()
                .Username(user.DisplayName)
                .Doc()
        return! Templating.Main ctx EndPoint.Private "Private section" [body]
    }
By on 5/23/2018 6:24 AM ()

I'd say that what's also interesting in the above solution is that piping partially applied functions inverts the order of execution. For example the left piped HTTPS redirect is applied to the URL context before rendering (as well as authorizations are checked before generating the HTML). Sort of like in category theory the exponential notation Y^X represents (notice the swap of X and Y) the morphismsX->Y Currying multi-argument functions by expressing a function as a lambda and then piping it into a high order function: this can be seen as the inversion of control (dependency injection) for functional programming.

it underpins a vast generalization of the Curry-Howard correspondence of proofs & programs

as wikipedia puts it, under currying. The fixed-point combinator is also related.

By on 5/24/2018 12:57 AM ()

Thank you very much for your help, as always.

Much appreciated!

By on 5/23/2018 7:21 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper