35 lines
874 B
Go
35 lines
874 B
Go
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
|
|
}
|
|
|
|
// ScratchCodeUnique checks the database if the generated scratch code
|
|
// is unique (not in the database yet)
|
|
func ScratchCodeIsUnique(scratchcode string) bool {
|
|
var dbitem models.MFAScratchCode
|
|
numrows, err := models.DB.NewSelect().Model(&dbitem).Where("code = ?", scratchcode).Count(context.Background())
|
|
if err != nil {
|
|
return false
|
|
}
|
|
|
|
if numrows != 0 {
|
|
return false
|
|
}
|
|
return true
|
|
}
|