recaptcha

package module
v0.0.0-...-2cf4483 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2020 License: BSD-3-Clause Imports: 11 Imported by: 1

README

recaptcha

Google ReCaptcha Helpers

Documentation

Overview

Package recaptcha handles reCaptcha (http://www.google.com/recaptcha) form submissions

This package is designed to be called from within an HTTP server or web framework which offers reCaptcha form inputs and requires them to be evaluated for correctness

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultValidateFailedHandler

func DefaultValidateFailedHandler(w http.ResponseWriter, r *http.Request, err error)

func Interceptor

func Interceptor(key interface{}) func(w http.ResponseWriter, r *http.Request) (ok bool, err error)

func MiddlewareContext

func MiddlewareContext(key interface{}, failed ValidationFailedHandler, next http.Handler) http.Handler

func ValidateContext

func ValidateContext(key interface{}, w http.ResponseWriter, r *http.Request) (ok bool, err error)

Types

type ReCaptcha

type ReCaptcha struct {
	PrivateKey  string
	Timeout     int8
	SkipFunc    func(r *http.Request) bool
	RealIPFunc  func(r *http.Request) string
	FailedFunc  ValidationFailedHandler
	MinScore    float32
	MaxFormSize int64
	Site        *Site
	Data        maps.Map
}

func New

func New(privateKey, publicKey string) *ReCaptcha

New creates new ReCaptcha object for allows the webserver or code evaluating the reCaptcha form input to set the reCaptcha private key (string) value, which will be different for every domain.

func (*ReCaptcha) Confirm

func (this *ReCaptcha) Confirm(remoteip, response string) (ok bool, err error)

Confirm is the public interface function. It calls check, which the client ip address, the challenge code from the reCaptcha form, and the client's response input to that challenge to determine whether or not the client answered the reCaptcha input question correctly. It returns a boolean value indicating whether or not the client answered correctly.

func (*ReCaptcha) FormCheck

func (this *ReCaptcha) FormCheck(w http.ResponseWriter, r *http.Request) (ok bool, err error)

func (*ReCaptcha) Middleware

func (this *ReCaptcha) Middleware(next http.Handler) http.Handler

func (*ReCaptcha) ProcessRequest

func (this *ReCaptcha) ProcessRequest(request *http.Request, realIP string) (result bool, err error)

ProcessRequest accepts the http.Request object, finds the reCaptcha form variables which were input and sent by HTTP POST to the server, then calls the recaptcha package's Confirm() method, which returns a boolean indicating whether or not the client answered the form correctly.

func (*ReCaptcha) Validate

func (this *ReCaptcha) Validate(w http.ResponseWriter, r *http.Request) (ok bool, err error)

type ReCaptchaServerError

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

func (ReCaptchaServerError) Err

func (this ReCaptchaServerError) Err() error

func (ReCaptchaServerError) Error

func (this ReCaptchaServerError) Error() string

type RecaptchaResponse

type RecaptchaResponse struct {
	Success     bool      `json:"success"`
	Score       float32   `json:"score"`
	Action      string    `json:"action"`
	ChallengeTS time.Time `json:"challenge_ts"`
	Hostname    string    `json:"hostname"`
	ErrorCodes  []string  `json:"error-codes"`
}

type Site

type Site struct {
	Key string
	// contains filtered or unexported fields
}

func NewSite

func NewSite(key string) *Site

func (*Site) HeaderScript

func (this *Site) HeaderScript() string

func (*Site) HeaderStyle

func (this *Site) HeaderStyle() string

func (*Site) Script

func (this *Site) Script(action string, form string) string

type ValidationFailedHandler

type ValidationFailedHandler func(w http.ResponseWriter, r *http.Request, err error)

Jump to

Keyboard shortcuts

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