go-urlsh/internal/db/multifactor.go

21 lines
476 B
Go
Raw Normal View History

2024-05-04 17:06:01 +02:00
package db
import (
"context"
"fmt"
"code.lila.network/adoralaura/go-urlsh/models"
)
func UserHasMFA(user models.User) (bool, error) {
numrows, err := models.DB.NewSelect().Model((*models.MFAConfig)(nil)).Where("username = ?", user.UserName).Where("active = ?", true).Count(context.Background())
if err != nil {
return false, fmt.Errorf("[UserHasMFA] error getting MFA count from database: %q", err)
}
if numrows >= 1 {
return true, nil
}
return false, nil
}