Documentation
¶
Overview ¶
Package hcaptcha provides hCaptcha integration for oCMS. Protects login forms from bots and automated attacks.
templ: version: v0.3.1001
Index ¶
- Constants
- func GetRemoteIP(r *http.Request) string
- func GetResponseFromForm(r *http.Request) string
- func HCaptchaPage(pc *adminviews.PageContext, data HCaptchaViewData) templ.Component
- type HCaptchaViewData
- type Module
- func (m *Module) AdminURL() string
- func (m *Module) GetSettings() Settings
- func (m *Module) Init(ctx *module.Context) error
- func (m *Module) IsEnabled() bool
- func (m *Module) Migrations() []module.Migration
- func (m *Module) RegisterAdminRoutes(r chi.Router)
- func (m *Module) RegisterRoutes(_ chi.Router)
- func (m *Module) ReloadSettings() error
- func (m *Module) RenderWidget() template.HTML
- func (m *Module) Shutdown() error
- func (m *Module) SidebarLabel() string
- func (m *Module) TemplateFuncs() template.FuncMap
- func (m *Module) TranslationsFS() embed.FS
- func (m *Module) Verify(response, remoteIP string) (*VerifyResponse, error)
- func (m *Module) VerifyFromRequest(req *VerifyRequest) (*VerifyRequest, error)
- type Settings
- type VerifyRequest
- type VerifyResponse
Constants ¶
const ( // HookAuthLoginWidget is called to render the captcha widget in login form. HookAuthLoginWidget = "auth.login_widget" // HookAuthBeforeLogin is called before login to verify captcha. HookAuthBeforeLogin = "auth.before_login" // HookFormCaptchaWidget is called to render captcha widget in public forms. HookFormCaptchaWidget = "form.captcha_widget" // HookFormCaptchaVerify is called to verify captcha on form submission. HookFormCaptchaVerify = "form.captcha_verify" )
Hook names for hCaptcha integration.
const ( TestSiteKey = "10000000-ffff-ffff-ffff-000000000001" TestSecretKey = "0x0000000000000000000000000000000000000000" )
hCaptcha test/debug keys for development. These always pass verification without showing a challenge. See: https://docs.hcaptcha.com/#integration-testing-test-keys
Variables ¶
This section is empty.
Functions ¶
func GetRemoteIP ¶
GetRemoteIP extracts the client IP from an HTTP request.
func GetResponseFromForm ¶
GetResponseFromForm extracts the h-captcha-response from an HTTP request.
func HCaptchaPage ¶ added in v0.9.0
func HCaptchaPage(pc *adminviews.PageContext, data HCaptchaViewData) templ.Component
Types ¶
type HCaptchaViewData ¶ added in v0.9.0
type Module ¶
type Module struct {
module.BaseModule
// contains filtered or unexported fields
}
Module implements the module.Module interface for the hCaptcha module.
func (*Module) GetSettings ¶
GetSettings returns a copy of the current settings (for use by other packages).
func (*Module) Migrations ¶
Migrations returns database migrations for the module.
func (*Module) RegisterAdminRoutes ¶
RegisterAdminRoutes registers admin routes for the module.
func (*Module) RegisterRoutes ¶
RegisterRoutes registers public routes for the module.
func (*Module) ReloadSettings ¶
ReloadSettings reloads settings from the database.
func (*Module) RenderWidget ¶
RenderWidget returns the hCaptcha widget HTML. SECURITY: Output is cast to template.HTML. Admin-controlled values (site key, theme, size) are escaped with template.HTMLEscapeString.
func (*Module) SidebarLabel ¶
SidebarLabel returns the display label for the admin sidebar.
func (*Module) TemplateFuncs ¶
TemplateFuncs returns template functions provided by the module.
func (*Module) TranslationsFS ¶
TranslationsFS returns the embedded filesystem containing module translations.
func (*Module) Verify ¶
func (m *Module) Verify(response, remoteIP string) (*VerifyResponse, error)
Verify checks the hCaptcha response token with the hCaptcha API.
func (*Module) VerifyFromRequest ¶
func (m *Module) VerifyFromRequest(req *VerifyRequest) (*VerifyRequest, error)
VerifyFromRequest verifies the captcha from a VerifyRequest struct.
type Settings ¶
type Settings struct {
Enabled bool
SiteKey string // Public site key
SecretKey string // Secret key for verification
Theme string // "light" or "dark"
Size string // "normal" or "compact"
}
Settings holds the hCaptcha configuration.
type VerifyRequest ¶
type VerifyRequest struct {
Response string // h-captcha-response from form
RemoteIP string // Client IP address
Verified bool // Set to true after successful verification
Error string // Error message if verification failed
ErrorCode string // Error code for i18n
}
VerifyRequest contains the data needed to verify a captcha response.