clean up unverified accounts after 1h

This commit is contained in:
Keiran 2025-08-06 06:20:54 +01:00
parent 9404620b39
commit 318440ac95
2 changed files with 13 additions and 0 deletions

View File

@ -173,6 +173,15 @@ func GetUserByEmail(ctx context.Context, email string) (*User, error) {
return &user, nil
}
func CleanupUnverifiedUsers(ctx context.Context) error {
_, err := Pool.Exec(ctx, `
DELETE FROM users
WHERE is_verified = false
AND created_at < NOW() - INTERVAL '1 hour'
`)
return err
}
func ValidateUserCredentials(ctx context.Context, username, password string) (*User, error) {
var user User
var passwordHash string

View File

@ -20,6 +20,10 @@ func HandleRoot(c echo.Context) error {
}
func HandleRegister(c echo.Context) error {
if err := db.CleanupUnverifiedUsers(c.Request().Context()); err != nil {
return c.JSON(http.StatusInternalServerError, map[string]string{"error": "Failed to cleanup old accounts"})
}
var req db.CreateUserRequest
if err := c.Bind(&req); err != nil {
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request body"})