initReCaptcha :: Maybe (Snaplet (Heist b)) -> SnapletInit b ReCaptcha
initReCaptcha heist =
  makeSnaplet "recaptcha" "ReCaptcha integration" Nothing $
    initialiser heist =<< do
      conf <- getSnapletUserConfig
      (,) <$> require conf "site_key"
          <*> require conf "secret_key"
 where
  require conf field = do
    v <- liftIO (Conf.lookup conf field)
    case v of
      Just v' -> return v'
      Nothing -> do
        spath <- BS.pack `fmap` getSnapletFilePath
        err   <- errorMsg (encodeUtf8 field <> " not in the config " <> spath
                           <> "/devel.cfg")
        fail (BS.unpack err)

-- | Same as 'initReCaptcha', but passing the site key and private key
-- explicitly - no configuration on the filesystem is required.
initReCaptcha :: Maybe (Snaplet (Heist b)) -> SnapletInit b ReCaptcha
initReCaptcha heist =
  makeSnaplet "recaptcha" "ReCaptcha integration" Nothing $
    initialiser heist =<< do
      conf <- getSnapletUserConfig
      (,) <$> require conf "site_key"
          <*> require conf "secret_key"
 where
  require conf field = do
    v <- liftIO (Conf.lookup conf field)
    case v of
      Just v' -> return v'
      Nothing -> do
        spath <- BS.pack `fmap` getSnapletFilePath
        err   <- errorMsg (encodeUtf8 field <> " not in the config " <> spath
                           <> "/devel.cfg")
        fail (BS.unpack err)

-- | Same as 'initReCaptcha', but passing the site key and private key
-- explicitly - no configuration on the filesystem is required.
initReCaptcha heist =
  makeSnaplet "recaptcha" "ReCaptcha integration" Nothing $
    initialiser heist =<< do
      conf <- getSnapletUserConfig
      (,) <$> require conf "site_key"
          <*> require conf "secret_key"
 where
  require conf field = do
    v <- liftIO (Conf.lookup conf field)
    case v of
      Just v' -> return v'
      Nothing -> do
        spath <- BS.pack `fmap` getSnapletFilePath
        err   <- errorMsg (encodeUtf8 field <> " not in the config " <> spath
                           <> "/devel.cfg")
        fail (BS.unpack err)

-- | Same as 'initReCaptcha', but passing the site key and private key
-- explicitly - no configuration on the filesystem is required.