| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Snap.Snaplet.ReCaptcha.Example
Contents
Description
Provides example usage for Snap.Snaplet.ReCaptcha.
- main :: IO ()
- initSample :: SnapletInit Sample Sample
- sampleTemplate :: Text
- initBlog :: forall b. (HasReCaptcha b, HasHeist b) => Snaplet (Heist b) -> SnapletInit b Blog
Main
main=serveSnapletdefaultConfiginitSample
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
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.