gocaptcha

package module
v0.0.0-...-8b3d844 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2012 License: BSD-2-Clause-Views Imports: 10 Imported by: 0

README

gocaptcha provides easy access to the reCaptcha API in go.

Package documentation at godoc.org/github.com/GeertJohan/gocaptcha.

TODO:

  • readme.md improvements with examples
  • tests (if possible automated with travis)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GoCaptcha

type GoCaptcha struct {
	// contains filtered or unexported fields
}

A GoCaptcha object identifies a single reCAPTCHA session (for one client). It is possible to store this object on a session activity and re-use it lateron for verification. This object keeps track of faulty verifications and makes sure any newly generated HTML contains an error message for the end-user, as provided by reCAPTCHA. Once a reCAPTCHA response was successfully verified this object should be discarded.

func NewGoCaptcha

func NewGoCaptcha(publickey string, privatekey string) *GoCaptcha

NewGoCaptha creates a new GoCaptcha object. Privatekey is the api key to be used with reCAPTCHA.

func (*GoCaptcha) HTMLBytes

func (gc *GoCaptcha) HTMLBytes() ([]byte, error)

Generate the reCAPTCHA HTML for this session and return it as byteslice. If error is not nil then something went wrong and the byteslice is empty.

func (*GoCaptcha) HTMLString

func (gc *GoCaptcha) HTMLString() (string, error)

Generate the reCAPTCHA HTML for this session and return it as string. If error is not nil then something went wrong and string is empty.

func (*GoCaptcha) Verify

func (gc *GoCaptcha) Verify(challenge string, response string, remoteaddr string) (bool, error)

Verify calls the reCAPTCHA API to verify if the given response by end-user is correct. Any returned error indicates a unsuccessfull api call. It does not indicate that the reCAPTCHA response by the end-user was faulty. Any returned error value is not to be shown to the end-user. When the error is nil, then response=false indicates that the reCAPTCHA response by the end-user was faulty. End-user will be notified of a faulty reCAPTCHA response when re-using this GoCaptcha object to generate HTML code again.

Expected parameters: challenge string, form value as sent by the http request. (Set by the reCAPTCHA in the end-users browser.) response string, form value as sent by the http request. (The answer given by the end-user.) remoteaddr string, The http.Request.RemoteAddr (e.g. "127.0.0.1:45435") from the client's endpoint.

func (*GoCaptcha) WriteHTML

func (gc *GoCaptcha) WriteHTML(w io.Writer) error

Generate the reCAPTCHA HTML for this session and write it to the given io.Writer.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL