packages feed

yesod-recaptcha2 (empty) → 0.1.0.0

raw patch · 5 files changed

+128/−0 lines, 5 filesdep +basedep +classy-prelude-yesoddep +http-conduitsetup-changed

Dependencies added: base, classy-prelude-yesod, http-conduit, yesod-auth

Files

+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) ncaq++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be+included in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,17 @@+# yesod-recaptcha2++~~~hs+import Import.ReCaptcha2+~~~++~~~hs+instance YesodReCaptcha App where+    reCaptchaSiteKey = return "foo"+    reCaptchaSecretKey = return "bar"+~~~+++~~~hs+<* reCaptcha+~~~+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ src/Yesod/ReCaptcha2.hs view
@@ -0,0 +1,57 @@+{-# LANGUAGE DeriveAnyClass    #-}+{-# LANGUAGE DeriveGeneric     #-}+{-# LANGUAGE NamedFieldPuns    #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE QuasiQuotes       #-}+{-# LANGUAGE TemplateHaskell   #-}+module Yesod.ReCaptcha2 (YesodReCaptcha(..), reCaptcha, mReCaptcha) where++import           ClassyPrelude.Yesod+import           Network.HTTP.Simple+import           Yesod.Auth++-- | default key is testing. you should impl reCaptchaSiteKey and reCaptchaSecretKey+class YesodAuth site => YesodReCaptcha site where+    reCaptchaSiteKey :: HandlerT site IO Text+    reCaptchaSiteKey = return "6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"+    reCaptchaSecretKey :: HandlerT site IO Text+    reCaptchaSecretKey = return "6LeIxAcTAAAAAGG-vFI1TnRWxMZNFuojJ4WifJWe"++data SiteverifyResponse = SiteverifyResponse { success :: Bool }+    deriving (Eq, Ord, Read, Show, Generic, FromJSON, ToJSON)++-- | for Applicative style form+reCaptcha :: YesodReCaptcha site => AForm (HandlerT site IO) ()+reCaptcha = formToAForm mReCaptcha++-- | for Monadic style form+mReCaptcha :: YesodReCaptcha site => MForm (HandlerT site IO) (FormResult (), [FieldView site])+mReCaptcha = do+    result <- liftHandlerT formResult+    return (result, [fieldViewSite])+  where formResult = do+            postParam <- lookupPostParam "g-recaptcha-response"+            case postParam of+                Nothing -> return $ FormMissing+                Just response -> do+                    secret <- reCaptchaSecretKey+                    s@SiteverifyResponse { success } <- liftIO $ do+                        req <- parseRequest "POST https://www.google.com/recaptcha/api/siteverify"+                        res <- httpJSON $+                            setRequestBodyURLEncoded+                            [("secret", encodeUtf8 secret), ("response", encodeUtf8 response)] req+                        return $ getResponseBody res+                    return $ if success+                        then FormSuccess ()+                        else FormFailure ["reCaptcha error"]+        fieldViewSite = FieldView+            { fvLabel = mempty+            , fvTooltip = Nothing+            , fvId = ""+            , fvInput = do+                    addScriptRemote "https://www.google.com/recaptcha/api.js"+                    siteKey <- handlerToWidget reCaptchaSiteKey+                    [whamlet|<div .g-recaptcha data-sitekey=#{siteKey}>|]+            , fvErrors = Nothing+            , fvRequired = True+            }
+ yesod-recaptcha2.cabal view
@@ -0,0 +1,32 @@+-- This file has been generated from package.yaml by hpack version 0.17.0.+--+-- see: https://github.com/sol/hpack++name:           yesod-recaptcha2+version:        0.1.0.0+synopsis:       yesod recaptcha2+description:    recaptcha2 for yesod-form+category:       Web+homepage:       https://github.com/ncaq/yesod-recaptcha2#readme+author:         ncaq+maintainer:     ncaq@ncaq.net+copyright:      ncaq+license:        MIT+license-file:   LICENSE+build-type:     Simple+cabal-version:  >= 1.10++extra-source-files:+    README.md++library+  hs-source-dirs:+      src+  build-depends:+      base >= 4.7 && < 5+    , classy-prelude-yesod+    , http-conduit+    , yesod-auth+  exposed-modules:+      Yesod.ReCaptcha2+  default-language: Haskell2010