Documentation
¶
Index ¶
- Constants
- func Factories() []string
- func Register(name string, f Factory)
- func UnregisterAll()
- type Captcha
- func (c *Captcha) CaptchaAction(scene string) func(w http.ResponseWriter, r *http.Request)
- func (c *Captcha) EnabledCheck(scene string, r *http.Request) (bool, error)
- func (c *Captcha) Verifier(r *http.Request, scene string) Verifier
- func (c *Captcha) Verify(r *http.Request, scene string, token string) (bool, error)
- type Config
- type Driver
- type Factory
- type Verifier
Constants ¶
const HeaderCaptchaEnabled = "X-Captcha-Enabled"
HeaderCaptchaEnabled header which contians if captcha is enabeld. If catpcha enabled,value "enabled" will be passed. Otherwise no header is passed.
const HeaderCaptchaName = "X-Captcha-Name"
HeaderCaptchaName header which contains the captcha name which used.
const HeaderReset = "X-Reset-Captcha"
HeaderReset header which should be passed in to reset captcha.
Variables ¶
This section is empty.
Functions ¶
func Factories ¶
func Factories() []string
Factories returns a sorted list of the names of the registered factories.
Types ¶
type Captcha ¶
type Captcha struct {
//Session captcha session store.
SessionStore *session.Store
//Enabled if captcha is enabled.
Enabled bool
//AddrWhiteList ip addr white list.Ip start with value in list doesn't need captcha.
AddrWhiteList []string
//DisabledScenes scenes which doesn't neec captcha.
DisabledScenes map[string]bool
//EnabledChecker function which check if captcha is necessarily.
EnabledChecker func(captcha *Captcha, scene string, r *http.Request) (bool, error)
// contains filtered or unexported fields
}
Captcha captcha struct.
func (*Captcha) CaptchaAction ¶
CaptchaAction action which afford capcha. Return captcha config json or empty object json if doesn't need captcha. If reset header is passed in,captcha will be reseted if supported.
func (*Captcha) EnabledCheck ¶
EnabledCheck check if http request in given scene need captcha. Return true if captcha is necessarily,and any error if raised.
type Config ¶
type Config struct {
Enabled bool
Driver string
DisabledScenes map[string]bool
AddrWhiteList []string
Config cache.ConfigMap
}
Config captcha config struct.
type Driver ¶
type Driver interface {
//Name return driver name.
Name() string
//MustCaptcha execute captcha to given http request and response and scene or reset value.
//Panic if any error rasied.
MustCaptcha(s *session.Store, w http.ResponseWriter, r *http.Request, scene string, reset bool)
//Verify verify if token is validated with given http rquest and scene.
//return verify result and any error raised.
Verify(s *session.Store, r *http.Request, scene string, token string) (bool, error)
}
Driver captcha driver interface.