email-validate 1.0.0

This commit is contained in:
Michael Snoyman 2013-02-02 19:51:15 +02:00
parent 38292d6357
commit c786b30afb
2 changed files with 12 additions and 1 deletions

View File

@ -60,6 +60,10 @@ import Text.Blaze (ToMarkup (toMarkup), preEscapedToMarkup, unsafeByteString)
import Text.Cassius
import Data.Time (Day, TimeOfDay(..))
import qualified Text.Email.Validate as Email
#if MIN_VERSION_email_validate(1, 0, 0)
import Data.Text.Encoding (encodeUtf8, decodeUtf8With)
import Data.Text.Encoding.Error (lenientDecode)
#endif
import Network.URI (parseURI)
import Database.Persist (PersistField)
import Database.Persist.Store (Entity (..))
@ -291,9 +295,16 @@ timeParser = do
emailField :: RenderMessage master FormMessage => Field sub master Text
emailField = Field
{ fieldParse = parseHelper $
#if MIN_VERSION_email_validate(1, 0, 0)
\s ->
case Email.canonicalizeEmail $ encodeUtf8 s of
Just e -> Right $ decodeUtf8With lenientDecode e
Nothing -> Left $ MsgInvalidEmail s
#else
\s -> if Email.isValid (unpack s)
then Right s
else Left $ MsgInvalidEmail s
#endif
, fieldView = \theId name attrs val isReq -> toWidget [hamlet|
$newline never
<input id="#{theId}" name="#{name}" *{attrs} type="email" :isReq:required="" value="#{either id id val}">

View File

@ -1,5 +1,5 @@
name: yesod-form
version: 1.2.1
version: 1.2.1.1
license: MIT
license-file: LICENSE
author: Michael Snoyman <michael@snoyman.com>