captcha: fix missing images

The captcha library's data struct wasn't being serialized/deserialized
fully, meaning the image was never stored. I never really wanted it to
be stored anyway, but as a compromise, the invite daemon now deletes
captcha images from the DB 20 minutes after generation.
This commit is contained in:
Harvey Tindall
2023-09-07 22:38:23 +01:00
parent 4607a30e6a
commit a0f1cd5814
3 changed files with 48 additions and 18 deletions
+17
View File
@@ -13,9 +13,26 @@ import (
"github.com/timshannon/badgerhold/v4"
)
const (
CAPTCHA_VALIDITY = 20 * 60 // Seconds
)
func (app *appContext) checkInvites() {
currentTime := time.Now()
for _, data := range app.storage.GetInvites() {
captchas := data.Captchas
captchasExpired := false
for key, capt := range data.Captchas {
if time.Now().After(capt.Generated.Add(CAPTCHA_VALIDITY * time.Second)) {
delete(captchas, key)
captchasExpired = true
}
}
if captchasExpired {
data.Captchas = captchas
app.storage.SetInvitesKey(data.Code, data)
}
if data.IsReferral {
continue
}