clean up unverified accounts after 1h
This commit is contained in:
parent
9404620b39
commit
318440ac95
@ -173,6 +173,15 @@ func GetUserByEmail(ctx context.Context, email string) (*User, error) {
|
|||||||
return &user, nil
|
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) {
|
func ValidateUserCredentials(ctx context.Context, username, password string) (*User, error) {
|
||||||
var user User
|
var user User
|
||||||
var passwordHash string
|
var passwordHash string
|
||||||
|
|||||||
@ -20,6 +20,10 @@ func HandleRoot(c echo.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func HandleRegister(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
|
var req db.CreateUserRequest
|
||||||
if err := c.Bind(&req); err != nil {
|
if err := c.Bind(&req); err != nil {
|
||||||
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request body"})
|
return c.JSON(http.StatusBadRequest, map[string]string{"error": "Invalid request body"})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user