Documentation
¶
Index ¶
- Constants
- Variables
- type DBRedisInterface
- type Error
- type LoginThrottle
- func (l *LoginThrottle) BuildKey(ip, userID string) string
- func (l *LoginThrottle) CanLogin(userID string, c echo.Context) (bool, error)
- func (l *LoginThrottle) GetAccessRegistry(key string) *LoginThrottleStatus
- func (l *LoginThrottle) OnLoginFail(userID string, c echo.Context) error
- func (l *LoginThrottle) OnLoginSuccess(userID string, c echo.Context) error
- func (l *LoginThrottle) SetAccessRegistry(lts *LoginThrottleStatus) error
- type LoginThrottleInterface
- type LoginThrottleStatus
- type ReCAPTCHA
- type VERSION
- type VerifyOption
Constants ¶
View Source
const ( // V2 recaptcha api v2 V2 VERSION = iota // V3 recaptcha api v3, more details can be found here : https://developers.google.com/recaptcha/docs/v3 V3 // DefaultThreshold Default minimin score when using V3 api DefaultThreshold float32 = 0.5 )
Variables ¶
View Source
var ( MaxErrors = 3 ResetTime = time.Minute * 10 WaitTime = time.Minute * 10 )
Functions ¶
This section is empty.
Types ¶
type DBRedisInterface ¶
type Error ¶
type Error struct {
// ErrorCodes contains any error codes from the recaptcha response.
ErrorCodes []string
// RequestError is true if the verify request to recaptcha failed.
RequestError bool
// contains filtered or unexported fields
}
Error custom error to pass ErrorCodes and RequestError to user.
type LoginThrottle ¶
func NewLoginThrottle ¶
func NewLoginThrottle(app bolo.App) *LoginThrottle
func (*LoginThrottle) BuildKey ¶
func (l *LoginThrottle) BuildKey(ip, userID string) string
func (*LoginThrottle) GetAccessRegistry ¶
func (l *LoginThrottle) GetAccessRegistry(key string) *LoginThrottleStatus
func (*LoginThrottle) OnLoginFail ¶
func (l *LoginThrottle) OnLoginFail(userID string, c echo.Context) error
func (*LoginThrottle) OnLoginSuccess ¶
func (l *LoginThrottle) OnLoginSuccess(userID string, c echo.Context) error
func (*LoginThrottle) SetAccessRegistry ¶
func (l *LoginThrottle) SetAccessRegistry(lts *LoginThrottleStatus) error
type LoginThrottleInterface ¶
type LoginThrottleStatus ¶
type LoginThrottleStatus struct {
Key string `json:"key"`
Count int `json:"count"`
// unix timestamp
WaitTime int64 `json:"wait_time"`
}
func (*LoginThrottleStatus) Can ¶
func (lts *LoginThrottleStatus) Can() bool
func (*LoginThrottleStatus) OnError ¶
func (lts *LoginThrottleStatus) OnError()
func (*LoginThrottleStatus) ToJSON ¶
func (lts *LoginThrottleStatus) ToJSON() string
type ReCAPTCHA ¶
type ReCAPTCHA struct {
Secret string
ReCAPTCHALink string
Version VERSION
Timeout time.Duration
// contains filtered or unexported fields
}
ReCAPTCHA recpatcha holder struct, make adding mocking code simpler.
func NewReCAPTCHA ¶
func NewReCAPTCHA(ReCAPTCHASecret string, version VERSION, timeout time.Duration) (ReCAPTCHA, error)
NewReCAPTCHA new ReCAPTCHA instance if version is set to V2 uses recatpcha v2 API, get your secret from https://www.google.com/recaptcha/admin
if version is set to V2 uses recatpcha v2 API, get your secret from https://g.co/recaptcha/v3
func (*ReCAPTCHA) Verify ¶
Verify returns `nil` if no error and the client solved the challenge correctly
func (*ReCAPTCHA) VerifyWithOptions ¶
func (r *ReCAPTCHA) VerifyWithOptions(challengeResponse string, options VerifyOption) error
VerifyWithOptions returns `nil` if no error and the client solved the challenge correctly and all options are matching `Threshold` and `Action` are ignored when using V2 version
Click to show internal directories.
Click to hide internal directories.