snaplet-recaptcha-1.0.1: A ReCAPTCHA verification snaplet with Heist integration and connection sharing.

Safe HaskellNone
LanguageHaskell2010

Snap.Snaplet.ReCaptcha.Example

Contents

Description

Provides example usage for Snap.Snaplet.ReCaptcha.

Synopsis

Main

main :: IO () Source

 main = serveSnaplet defaultConfig initSample

You can load this into GHCi and run it, with full logging to stdout/stderr

>>> :main --verbose --access-log= --error-log=

initSample :: SnapletInit Sample Sample Source

Requires 'snaplets/heist/templates/sample.tpl' - a suggested version of which is available in this module as sampleTemplate.

This reads the ReCaptcha configuration as an ordinary snaplet config on the filesystem as per initReCaptcha (snapletsrecaptchadevel.cfg).

Necessities

sampleTemplate :: Text Source

Heist template, written to $PWD/snaplets/heist/recaptcha-example.tpl

sampleTemplate ≈
  <html>
   <head>
     <recaptcha-script />
   </head>
   <body>
     <form method='POST'>
       <input type='text' name='name' placeholder='Name'>
       <input type='text' name='email' placeholder='Email'>
       <br>
       <textarea class='field' name='content' rows='20' placeholder='Content'></textarea>
       <br>
       <recaptcha-div />
       <input type='submit' value='Comment'>
     </form>
   </body>
  </html>

Implementation

initBlog :: forall b. (HasReCaptcha b, HasHeist b) => Snaplet (Heist b) -> SnapletInit b Blog Source

A "blog" snaplet which reads hypothetical "posts" by their id, and displays a comment form there.

GET on posts/:id → a comment form

POST on posts/:id → the comment poster which verifies that the user correctly responded to the captcha.