mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 02:09:01 +02:00
feat: hCaptcha middleware
This commit is contained in:
34
internal/net/gphttp/middleware/captcha/session.go
Normal file
34
internal/net/gphttp/middleware/captcha/session.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package captcha
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/hex"
|
||||
"time"
|
||||
|
||||
_ "embed"
|
||||
|
||||
"github.com/yusing/go-proxy/internal/jsonstore"
|
||||
"github.com/yusing/go-proxy/internal/utils"
|
||||
)
|
||||
|
||||
type CaptchaSession struct {
|
||||
ID string `json:"id"`
|
||||
|
||||
Expiry time.Time `json:"expiry"`
|
||||
}
|
||||
|
||||
var CaptchaSessions = jsonstore.Store[*CaptchaSession]("captcha_sessions")
|
||||
|
||||
func newCaptchaSession(p Provider) *CaptchaSession {
|
||||
buf := make([]byte, 32)
|
||||
_, _ = rand.Read(buf)
|
||||
now := utils.TimeNow()
|
||||
return &CaptchaSession{
|
||||
ID: hex.EncodeToString(buf),
|
||||
Expiry: now.Add(p.SessionExpiry()),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *CaptchaSession) expired() bool {
|
||||
return utils.TimeNow().After(s.Expiry)
|
||||
}
|
||||
Reference in New Issue
Block a user