Added email field
This commit is contained in:
parent
ecd39ed587
commit
93d71a4779
@ -44,6 +44,7 @@ module Yesod.Form
|
|||||||
, jqueryDayFieldProfile
|
, jqueryDayFieldProfile
|
||||||
, timeFieldProfile
|
, timeFieldProfile
|
||||||
, htmlFieldProfile
|
, htmlFieldProfile
|
||||||
|
, emailFieldProfile
|
||||||
-- * Pre-built fields
|
-- * Pre-built fields
|
||||||
, stringField
|
, stringField
|
||||||
, maybeStringField
|
, maybeStringField
|
||||||
@ -66,12 +67,15 @@ module Yesod.Form
|
|||||||
, boolField
|
, boolField
|
||||||
, jqueryAutocompleteField
|
, jqueryAutocompleteField
|
||||||
, maybeJqueryAutocompleteField
|
, maybeJqueryAutocompleteField
|
||||||
|
, emailField
|
||||||
|
, maybeEmailField
|
||||||
-- * Pre-built inputs
|
-- * Pre-built inputs
|
||||||
, stringInput
|
, stringInput
|
||||||
, maybeStringInput
|
, maybeStringInput
|
||||||
, boolInput
|
, boolInput
|
||||||
, dayInput
|
, dayInput
|
||||||
, maybeDayInput
|
, maybeDayInput
|
||||||
|
, emailInput
|
||||||
-- * Template Haskell
|
-- * Template Haskell
|
||||||
, share2
|
, share2
|
||||||
, mkToForm
|
, mkToForm
|
||||||
@ -495,7 +499,7 @@ htmlField label tooltip = requiredFieldHelper htmlFieldProfile
|
|||||||
, fpTooltip = tooltip
|
, fpTooltip = tooltip
|
||||||
}
|
}
|
||||||
|
|
||||||
maybeHtmlField :: Html () -> Html () -> FormletField sub y (Maybe (Html ())) -- FIXME make label and tooltip Strings instead
|
maybeHtmlField :: Html () -> Html () -> FormletField sub y (Maybe (Html ()))
|
||||||
maybeHtmlField label tooltip = optionalFieldHelper htmlFieldProfile
|
maybeHtmlField label tooltip = optionalFieldHelper htmlFieldProfile
|
||||||
{ fpLabel = label
|
{ fpLabel = label
|
||||||
, fpTooltip = tooltip
|
, fpTooltip = tooltip
|
||||||
@ -658,7 +662,9 @@ maybeStringInput n =
|
|||||||
|
|
||||||
boolInput :: String -> FormInput sub master Bool
|
boolInput :: String -> FormInput sub master Bool
|
||||||
boolInput n = GForm $ \env _ -> return
|
boolInput n = GForm $ \env _ -> return
|
||||||
(FormSuccess $ isJust $ lookup n env, mempty, UrlEncoded) -- FIXME
|
(FormSuccess $ isJust $ lookup n env, return $ addBody [$hamlet|
|
||||||
|
%input#$n$!type=checkbox!name=$n$
|
||||||
|
|], UrlEncoded)
|
||||||
|
|
||||||
dayInput :: String -> FormInput sub master Day
|
dayInput :: String -> FormInput sub master Day
|
||||||
dayInput n =
|
dayInput n =
|
||||||
@ -811,3 +817,35 @@ jqueryAutocompleteFieldProfile src = FieldProfile
|
|||||||
, fpLabel = mempty
|
, fpLabel = mempty
|
||||||
, fpTooltip = mempty
|
, fpTooltip = mempty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emailFieldProfile :: FieldProfile s y String
|
||||||
|
emailFieldProfile = FieldProfile
|
||||||
|
{ fpParse = Right -- FIXME validation
|
||||||
|
, fpRender = id
|
||||||
|
, fpHamlet = \name val isReq -> [$hamlet|
|
||||||
|
%input#$name$!name=$name$!type=email!:isReq:required!value=$val$
|
||||||
|
|]
|
||||||
|
, fpWidget = const $ return ()
|
||||||
|
, fpName = Nothing
|
||||||
|
, fpLabel = mempty
|
||||||
|
, fpTooltip = mempty
|
||||||
|
}
|
||||||
|
|
||||||
|
emailField :: Html () -> Html () -> FormletField sub y String
|
||||||
|
emailField label tooltip = requiredFieldHelper emailFieldProfile
|
||||||
|
{ fpLabel = label
|
||||||
|
, fpTooltip = tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
maybeEmailField :: Html () -> Html () -> FormletField sub y (Maybe String)
|
||||||
|
maybeEmailField label tooltip = optionalFieldHelper emailFieldProfile
|
||||||
|
{ fpLabel = label
|
||||||
|
, fpTooltip = tooltip
|
||||||
|
}
|
||||||
|
|
||||||
|
emailInput :: String -> FormInput sub master String
|
||||||
|
emailInput n =
|
||||||
|
mapFormXml fieldsToInput $
|
||||||
|
requiredFieldHelper emailFieldProfile
|
||||||
|
{ fpName = Just n
|
||||||
|
} Nothing
|
||||||
|
|||||||
@ -302,7 +302,7 @@ getEmailRegisterR = do
|
|||||||
postEmailRegisterR :: YesodAuth master => GHandler Auth master RepHtml
|
postEmailRegisterR :: YesodAuth master => GHandler Auth master RepHtml
|
||||||
postEmailRegisterR = do
|
postEmailRegisterR = do
|
||||||
ae <- getAuthEmailSettings
|
ae <- getAuthEmailSettings
|
||||||
email <- runFormPost' $ stringInput "email" -- FIXME checkEmail
|
email <- runFormPost' $ emailInput "email"
|
||||||
y <- getYesod
|
y <- getYesod
|
||||||
mecreds <- liftIO $ getEmailCreds ae email
|
mecreds <- liftIO $ getEmailCreds ae email
|
||||||
(lid, verKey) <-
|
(lid, verKey) <-
|
||||||
@ -367,7 +367,7 @@ postEmailLoginR :: YesodAuth master => GHandler Auth master ()
|
|||||||
postEmailLoginR = do
|
postEmailLoginR = do
|
||||||
ae <- getAuthEmailSettings
|
ae <- getAuthEmailSettings
|
||||||
(email, pass) <- runFormPost' $ (,)
|
(email, pass) <- runFormPost' $ (,)
|
||||||
<$> stringInput "email" -- FIXME valid e-mail?
|
<$> emailInput "email"
|
||||||
<*> stringInput "password"
|
<*> stringInput "password"
|
||||||
y <- getYesod
|
y <- getYesod
|
||||||
mecreds <- liftIO $ getEmailCreds ae email
|
mecreds <- liftIO $ getEmailCreds ae email
|
||||||
|
|||||||
@ -26,7 +26,6 @@ module Yesod.Widget
|
|||||||
, extractBody
|
, extractBody
|
||||||
) where
|
) where
|
||||||
|
|
||||||
-- FIXME add support for script contents
|
|
||||||
import Data.List (nub)
|
import Data.List (nub)
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
import Control.Monad.Trans.Writer
|
import Control.Monad.Trans.Writer
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user