refactor: move auth, GDPR, and booking cleanup to centralized scheduler

Convert CleanupRevokedJTIs to return (int, error) and remove StartJTICleanup goroutine. Add CleanupStaleLoginEntries and CleanupGDPRExportCache for centralized scheduler. Add clock.London timezone location.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
2026-07-07 00:10:00 +01:00
co-authored by Sisyphus
parent a4fa75154d
commit e86248b27c
7 changed files with 276 additions and 79 deletions
+16 -27
View File
@@ -1,10 +1,10 @@
package auth
import (
"context"
"crussell/auth"
"crussell/clock"
"crussell/db"
"github.com/jackc/pgx/v5"
"crussell/internal/dav"
"crussell/internal/validators"
"crussell/internal/zxcvbnjs"
@@ -16,21 +16,22 @@ import (
"log"
"net/http"
"github.com/go-chi/chi/v5/middleware"
"github.com/jackc/pgx/v5"
"os"
"regexp"
"strings"
"sync"
"time"
"github.com/go-chi/chi/v5/middleware"
"github.com/nyaruka/phonenumbers"
"golang.org/x/crypto/bcrypt"
"golang.org/x/text/cases"
"golang.org/x/text/language"
)
const maxLoginInProgress = 20
// Login state management
@@ -39,30 +40,18 @@ var (
loginInProgress = make(map[string]time.Time)
)
func init() {
go func() {
ticker := time.NewTicker(1 * time.Hour)
defer ticker.Stop()
for range ticker.C {
func() {
defer func() {
if r := recover(); r != nil {
log.Printf("Panic recovered in login state cleanup ticker: %v", r)
}
}()
loginStateMu.Lock()
now := clock.Now()
// Clean up stuck loginInProgress entries (older than 30s)
for userID, startedAt := range loginInProgress {
if now.Sub(startedAt) > 30*time.Second {
delete(loginInProgress, userID)
}
}
loginStateMu.Unlock()
}()
// CleanupStaleLoginEntries removes stuck loginInProgress entries older than 30 seconds.
// Called by the centralised jobs scheduler.
func CleanupStaleLoginEntries(ctx context.Context) (int, error) {
loginStateMu.Lock()
defer loginStateMu.Unlock()
now := clock.Now()
for userID, startedAt := range loginInProgress {
if now.Sub(startedAt) > 30*time.Second {
delete(loginInProgress, userID)
}
}()
}
return 0, nil
}
type RegisterRequest struct {