Package altcha is a middleware that provides self-hosted ALTCHA proof-of-work captchas for Flamego.
go get github.com/flamego/altcha<!-- templates/home.tmpl -->
<form method="POST">
{{.AltchaHTML}}
<button>Submit</button>
</form>package main
import (
"net/http"
"os"
"github.com/flamego/altcha"
"github.com/flamego/flamego"
"github.com/flamego/template"
)
func main() {
f := flamego.Classic()
f.Use(template.Templater())
f.Use(altcha.Challenger(
altcha.Options{
Secret: []byte(os.Getenv("ALTCHA_SECRET")),
},
))
f.Get("/", func(t template.Template, data template.Data, c altcha.Challenge) {
data["AltchaHTML"] = c.HTML()
t.HTML(http.StatusOK, "home")
})
f.Post("/", func(w http.ResponseWriter, r *http.Request, c altcha.Challenge) {
if err := c.Verify(r.PostFormValue(altcha.FieldName)); err != nil {
w.WriteHeader(http.StatusBadRequest)
_, _ = w.Write([]byte(err.Error()))
return
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte("Verified!"))
})
f.Run()
}- Read documentation and examples.
- Please file an issue or start a discussion on the flamego/flamego repository.
This project is under the MIT License. See the LICENSE file for the full license text.