models

package
v0.0.0-...-d2171c4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 14, 2026 License: EUPL-1.2 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TransportsFromWebAuthn

func TransportsFromWebAuthn(transports []protocol.AuthenticatorTransport) string

TransportsFromWebAuthn converts WebAuthn transports to a comma-separated string.

Types

type Credential

type Credential struct {
	bun.BaseModel `bun:"table:credentials,alias:c"`

	ID              int64     `bun:",pk,autoincrement" json:"id"`
	UserID          int64     `bun:",notnull" json:"user_id"`
	CredentialID    []byte    `bun:",unique,notnull" json:"-"`
	PublicKey       []byte    `bun:",notnull" json:"-"`
	AAGUID          []byte    `json:"-"`
	SignCount       uint32    `bun:",default:0" json:"-"`
	Transports      string    `json:"-"` // comma-separated
	Name            string    `bun:",notnull" json:"name"`
	BackupEligible  bool      `bun:",default:false" json:"-"`
	BackupState     bool      `bun:",default:false" json:"-"`
	AttestationType string    `json:"-"`
	CreatedAt       time.Time `bun:",nullzero,notnull,default:current_timestamp" json:"created_at"`
	DeletedAt       time.Time `bun:",soft_delete,nullzero" json:"-"`
}

Credential stores a WebAuthn credential for a user.

func NewCredentialFromWebAuthn

func NewCredentialFromWebAuthn(userID int64, cred *webauthn.Credential) *Credential

NewCredentialFromWebAuthn creates a Credential from a webauthn.Credential.

func (*Credential) ToWebAuthn

func (c *Credential) ToWebAuthn() webauthn.Credential

ToWebAuthn converts the database credential to a webauthn.Credential.

type EmailVerificationToken

type EmailVerificationToken struct {
	bun.BaseModel `bun:"table:email_verification_tokens,alias:evt"`

	ID        int64     `bun:",pk,autoincrement" json:"id"`
	UserID    int64     `bun:",notnull" json:"user_id"`
	TokenHash string    `bun:",unique,notnull" json:"-"` // SHA256 hash
	ExpiresAt time.Time `bun:",notnull" json:"expires_at"`
	CreatedAt time.Time `bun:",nullzero,notnull,default:current_timestamp" json:"created_at"`
	DeletedAt time.Time `bun:",soft_delete,nullzero" json:"-"`
}

EmailVerificationToken stores a hashed token for email verification.

type RecoveryCode

type RecoveryCode struct {
	bun.BaseModel `bun:"table:recovery_codes,alias:rc"`

	ID        int64      `bun:",pk,autoincrement" json:"id"`
	UserID    int64      `bun:",notnull" json:"user_id"`
	CodeHash  string     `bun:",notnull" json:"-"`
	Used      bool       `bun:",notnull,default:false" json:"used"`
	CreatedAt time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"created_at"`
	UsedAt    *time.Time `json:"used_at,omitempty"`
	DeletedAt time.Time  `bun:",soft_delete,nullzero" json:"-"`
}

RecoveryCode stores a hashed recovery code for account recovery.

type User

type User struct {
	bun.BaseModel `bun:"table:users,alias:u"`

	ID              int64      `bun:",pk,autoincrement" json:"id"`
	Username        string     `bun:",unique,notnull" json:"username"`
	Email           *string    `bun:",unique" json:"email,omitempty"`
	EmailVerified   bool       `bun:",notnull,default:false" json:"email_verified"`
	EmailVerifiedAt *time.Time `json:"email_verified_at,omitempty"`
	Name            string     `bun:",nullzero" json:"name,omitempty"`
	Bio             string     `bun:",nullzero" json:"bio,omitempty"`
	CreatedAt       time.Time  `bun:",nullzero,notnull,default:current_timestamp" json:"created_at"`
	UpdatedAt       time.Time  `bun:",nullzero" json:"updated_at"`
	DeletedAt       time.Time  `bun:",soft_delete,nullzero" json:"-"`

	// Associations
	Credentials []Credential `bun:"rel:has-many,join:id=user_id" json:"credentials,omitempty"`
}

User represents an authenticated user with WebAuthn credentials.

func (*User) WebAuthnCredentials

func (u *User) WebAuthnCredentials() []webauthn.Credential

WebAuthnCredentials returns the user's WebAuthn credentials.

func (*User) WebAuthnDisplayName

func (u *User) WebAuthnDisplayName() string

WebAuthnDisplayName returns the user's display name. Returns Name if set, otherwise falls back to Username.

func (*User) WebAuthnID

func (u *User) WebAuthnID() []byte

WebAuthnID returns the user's ID as a byte slice for WebAuthn.

func (*User) WebAuthnIcon

func (u *User) WebAuthnIcon() string

WebAuthnIcon returns an empty string (deprecated in WebAuthn spec).

func (*User) WebAuthnName

func (u *User) WebAuthnName() string

WebAuthnName returns the user's username.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址