2022-03-05 21:35:17 +03:00
|
|
|
module Route.Secret exposing (Data, Model, Msg, route)
|
2021-12-30 04:18:37 +03:00
|
|
|
|
|
|
|
import DataSource exposing (DataSource)
|
|
|
|
import DataSource.File
|
|
|
|
import Head
|
|
|
|
import Head.Seo as Seo
|
|
|
|
import Html
|
|
|
|
import Html.Attributes as Attr
|
|
|
|
import Pages.PageUrl exposing (PageUrl)
|
|
|
|
import Pages.Url
|
|
|
|
import Route
|
2022-03-05 20:50:01 +03:00
|
|
|
import RouteBuilder exposing (StatefulRoute, StatelessRoute, StaticPayload)
|
2021-12-30 04:18:37 +03:00
|
|
|
import Server.Request as Request
|
2022-01-18 07:56:37 +03:00
|
|
|
import Server.Response as Response exposing (Response)
|
2021-12-30 04:18:37 +03:00
|
|
|
import Shared
|
|
|
|
import View exposing (View)
|
|
|
|
|
|
|
|
|
|
|
|
type alias Model =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
type alias Msg =
|
2022-01-06 01:09:37 +03:00
|
|
|
()
|
2021-12-30 04:18:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
type alias RouteParams =
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2022-03-05 21:35:17 +03:00
|
|
|
route : StatelessRoute RouteParams Data
|
|
|
|
route =
|
2022-03-05 20:50:01 +03:00
|
|
|
RouteBuilder.serverRender
|
2021-12-30 04:18:37 +03:00
|
|
|
{ head = head
|
|
|
|
, data = data
|
|
|
|
}
|
2022-03-05 20:50:01 +03:00
|
|
|
|> RouteBuilder.buildNoState { view = view }
|
2021-12-30 04:18:37 +03:00
|
|
|
|
|
|
|
|
|
|
|
type Data
|
|
|
|
= LoggedIn LoggedInInfo
|
|
|
|
| NotLoggedIn
|
|
|
|
|
|
|
|
|
|
|
|
type alias LoggedInInfo =
|
|
|
|
{ username : String
|
|
|
|
, secretNote : String
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-03-08 19:57:46 +03:00
|
|
|
data : RouteParams -> Request.Parser (DataSource (Response Data))
|
2021-12-30 04:18:37 +03:00
|
|
|
data routeParams =
|
2021-12-31 22:14:23 +03:00
|
|
|
Request.oneOf
|
2021-12-30 04:18:37 +03:00
|
|
|
[ Request.expectCookie "username"
|
2021-12-31 22:14:23 +03:00
|
|
|
|> Request.map
|
2021-12-30 04:18:37 +03:00
|
|
|
(\username ->
|
|
|
|
username
|
|
|
|
|> LoggedInInfo
|
|
|
|
|> DataSource.succeed
|
2021-12-30 20:45:27 +03:00
|
|
|
|> DataSource.andMap (DataSource.File.rawFile "examples/pokedex/content/secret-note.txt")
|
2021-12-30 04:18:37 +03:00
|
|
|
|> DataSource.map LoggedIn
|
2022-01-18 07:56:37 +03:00
|
|
|
|> DataSource.map Response.render
|
2021-12-30 04:18:37 +03:00
|
|
|
)
|
2021-12-31 22:14:23 +03:00
|
|
|
, Request.succeed
|
|
|
|
(NotLoggedIn
|
|
|
|
|> DataSource.succeed
|
2022-01-18 07:56:37 +03:00
|
|
|
|> DataSource.map Response.render
|
2021-12-31 22:14:23 +03:00
|
|
|
--"/login"
|
|
|
|
-- |> ServerResponse.temporaryRedirect
|
|
|
|
-- --|> ServerResponse.withStatusCode 404
|
|
|
|
-- |> PageServerResponse.ServerResponse
|
|
|
|
-- |> DataSource.succeed
|
|
|
|
)
|
2021-12-30 04:18:37 +03:00
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
head :
|
|
|
|
StaticPayload Data RouteParams
|
|
|
|
-> List Head.Tag
|
|
|
|
head static =
|
|
|
|
Seo.summary
|
|
|
|
{ canonicalUrlOverride = Nothing
|
|
|
|
, siteName = "elm-pages"
|
|
|
|
, image =
|
|
|
|
{ url = Pages.Url.external "TODO"
|
|
|
|
, alt = "elm-pages logo"
|
|
|
|
, dimensions = Nothing
|
|
|
|
, mimeType = Nothing
|
|
|
|
}
|
|
|
|
, description = "TODO"
|
|
|
|
, locale = Nothing
|
|
|
|
, title = "TODO title" -- metadata.title -- TODO
|
|
|
|
}
|
|
|
|
|> Seo.website
|
|
|
|
|
|
|
|
|
|
|
|
view :
|
|
|
|
Maybe PageUrl
|
|
|
|
-> Shared.Model
|
|
|
|
-> StaticPayload Data RouteParams
|
|
|
|
-> View Msg
|
|
|
|
view maybeUrl sharedModel static =
|
|
|
|
case static.data of
|
|
|
|
LoggedIn loggedInInfo ->
|
|
|
|
{ title = "Secret"
|
|
|
|
, body =
|
|
|
|
[ Html.main_ [ Attr.style "max-width" "800px" ]
|
|
|
|
[ Html.h1 [] [ Html.text "This is a secret page" ]
|
|
|
|
, Html.p []
|
|
|
|
[ Html.text <| "Welcome, " ++ loggedInInfo.username ++ "!"
|
|
|
|
]
|
|
|
|
, Html.p []
|
|
|
|
[ Html.text loggedInInfo.secretNote
|
|
|
|
]
|
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
NotLoggedIn ->
|
|
|
|
{ title = "Secret"
|
|
|
|
, body =
|
|
|
|
[ Html.main_ [ Attr.style "max-width" "800px" ]
|
|
|
|
[ Html.h1 [] [ Html.text "You're not logged in" ]
|
|
|
|
, Route.link Route.Login
|
|
|
|
[]
|
2021-12-30 20:31:24 +03:00
|
|
|
[ Html.text <| "Login" ]
|
2021-12-30 04:18:37 +03:00
|
|
|
]
|
|
|
|
]
|
|
|
|
}
|