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

Safe HaskellNone
LanguageHaskell2010

Snap.Snaplet.ReCaptcha.Example

Contents

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 simple asks for your site and private key through stdin.

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, routing GET on /posts/:id to display a post, and POST on /posts/:id to add a comment to them. For loose, useless definitions of "post" and "comment" - this snaplet is only for demonstration purposes.