Skip to content

Commit

Permalink
define form layout
Browse files Browse the repository at this point in the history
  • Loading branch information
nieled committed Aug 6, 2022
1 parent 9549168 commit 1b43dda
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ dependencies:
- cookie
- data-has
- digestive-functors
- digestive-functors-blaze
- digestive-functors-scotty
- exceptions
- hedis
Expand Down
45 changes: 41 additions & 4 deletions src/Adapter/HTTP/Web/Auth.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,29 @@ import Control.Monad.Reader ( MonadIO
import Data.Text ( Text
, pack
)
import Domain.Auth
import Domain.Auth ( Auth(Auth)
, AuthRepo
, EmailVerificationError
( EmailVerificationErrorInvalidCode
)
, EmailVerificationNotif
, RegistrationError
( RegistrationErrorEmailTaken
)
, SessionRepo
, getUser
, mkEmail
, mkPassword
, rawEmail
, register
, verifyEmail
)
import Katip
import qualified Text.Blaze.Html5 as H
import Text.Blaze.Html5 ( (!) )
import qualified Text.Blaze.Html5.Attributes as A
import qualified Text.Digestive as DF
import Text.Digestive.Blaze.Html5 as DH
import Text.Digestive.Form ( (.:) )
import Text.Digestive.Scotty
import Web.Scotty.Trans
Expand Down Expand Up @@ -77,13 +94,33 @@ verifyEmailPage message = mainLayout "Email verification" $ do
H.div $ H.toHtml message
H.div $ H.a ! A.href "/auth/login" $ "Login"

registerPage :: DF.View [Text] -> [Text] -> H.Html
registerPage = undefined

authForm :: (Monad m) => DF.Form [Text] m Auth
authForm = Auth <$> "email" .: emailForm <*> "password" .: passwordForm
where
emailForm = DF.validate (toResult . asText . mkEmail) (DF.text Nothing)
passwordForm = DF.validate (toResult . asText . mkPassword) (DF.text Nothing)
asText :: (Show e) => Either [e] d -> Either [Text] d
asText = left (pack . show <$>)

authFormLayout :: DF.View [Text] -> Text -> Text -> [Text] -> H.Html
authFormLayout view formTitle action msgs = formLayout view action $ do
H.h2 $ H.toHtml formTitle
H.div $ errorList msgs
H.div $ do
H.label "Email"
DH.inputText "email" view
H.div $ errorList' "email"
H.div $ do
H.label "Password"
DH.inputPassword "password" view
H.div $ errorList' "password"
H.input ! A.type_ "submit" ! A.value "Submit"
where
errorList' path = errorList . mconcat $ DF.errors path view
errorList msgs = H.ul $ do
H.li . H.toHtml . show $ msgs -- TODO: create a `H.li` for each error
errorItem :: Text -> H.Html
errorItem = H.li . H.toHtml

registerPage :: DF.View [Text] -> [Text] -> H.Html
registerPage = undefined
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ packages:
#
extra-deps:
- digestive-functors-0.8.4.2
- digestive-functors-blaze-0.6.2.0
- git: https://github.com/mmartin/digestive-functors-scotty.git
commit: aca9dd5c3df6c64c24b80357051e3ba7ca974b60

Expand Down
7 changes: 7 additions & 0 deletions stack.yaml.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ packages:
sha256: 53ce82c7f0c60c10009b1b764b537117a4ab402bbe1a147fba5ad2263acb3025
original:
hackage: digestive-functors-0.8.4.2
- completed:
hackage: digestive-functors-blaze-0.6.2.0@sha256:3aae259265b8517fb7efe2a7681d846e01f52c22f49f193aff550a1630f182d0,841
pantry-tree:
size: 289
sha256: 2584d35cf054e3daa2f961d7b68e1c0bafd68f99284c4e76509fc455a0380315
original:
hackage: digestive-functors-blaze-0.6.2.0
- completed:
name: digestive-functors-scotty
version: 0.2.0.2
Expand Down
3 changes: 3 additions & 0 deletions uaa-hs.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ library
, cookie
, data-has
, digestive-functors
, digestive-functors-blaze
, digestive-functors-scotty
, exceptions
, hedis
Expand Down Expand Up @@ -113,6 +114,7 @@ executable uaa-hs-exe
, cookie
, data-has
, digestive-functors
, digestive-functors-blaze
, digestive-functors-scotty
, exceptions
, hedis
Expand Down Expand Up @@ -165,6 +167,7 @@ test-suite uaa-hs-test
, cookie
, data-has
, digestive-functors
, digestive-functors-blaze
, digestive-functors-scotty
, exceptions
, hedis
Expand Down

0 comments on commit 1b43dda

Please sign in to comment.