veza/veza-backend-api/internal/models/mfa_config.go
2025-12-03 20:29:37 +01:00

37 lines
1.1 KiB
Go

package models
import (
"time"
"github.com/google/uuid"
"gorm.io/gorm"
)
// MFAConfig represents multi-factor authentication configuration
type MFAConfig struct {
ID uuid.UUID `gorm:"type:uuid;primaryKey" json:"id"`
UserID uuid.UUID `gorm:"type:uuid;not null;uniqueIndex" json:"user_id"`
Secret string `gorm:"not null" json:"-"`
BackupCodes string `gorm:"type:text" json:"-"` // JSON array of backup codes
IsEnabled bool `gorm:"default:false" json:"is_enabled"`
LastUsedAt *time.Time `json:"last_used_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
// Relations
User User `gorm:"foreignKey:UserID" json:"-"`
}
// BeforeCreate hook to generate UUID if not set
func (m *MFAConfig) BeforeCreate(tx *gorm.DB) error {
if m.ID == uuid.Nil {
m.ID = uuid.New()
}
return nil
}
// TableName returns the table name for the MFAConfig model
func (MFAConfig) TableName() string {
return "mfa_configs"
}