mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-20 12:42:34 +02:00
34 lines
654 B
Go
34 lines
654 B
Go
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)
|
|
}
|