2023-06-16 13:16:47 +02:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"log"
|
2024-05-04 17:06:01 +02:00
|
|
|
|
|
|
|
"code.lila.network/adoralaura/go-urlsh/models"
|
|
|
|
"github.com/jasonlvhit/gocron"
|
2023-06-16 13:16:47 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func CleanupLoginsCronJob() {
|
2024-05-04 17:06:01 +02:00
|
|
|
err := gocron.Every(5).Minutes().Do(CleanupLogins)
|
2023-06-16 13:16:47 +02:00
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
<-gocron.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
func CleanupLogins() {
|
|
|
|
_, err := models.DB.NewDelete().Table("logins").Where("expires < NOW()").Exec(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("[CleanupLogins] Error deleting logins: %v\n", err)
|
|
|
|
}
|
2024-05-04 17:06:01 +02:00
|
|
|
|
|
|
|
_, err = models.DB.NewDelete().Table("logintransactions").Where("expires < NOW()").Exec(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("[CleanupLogins] Error deleting login transactions: %v\n", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
_, err = models.DB.NewDelete().Table("multifactor").Where("expiresat < NOW()").Where("active = false").Exec(context.Background())
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("[CleanupLogins] Error deleting login transactions: %v\n", err)
|
|
|
|
}
|
|
|
|
//log.Printf("Cleaned up logins")
|
2023-06-16 13:16:47 +02:00
|
|
|
}
|