model

package
v0.0.0-...-183af2d Latest Latest
Warning

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

Go to latest
Published: May 22, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CountCredentialByUserID

func CountCredentialByUserID(db *gorm.DB, userID uint) int

func CreateAuthSession

func CreateAuthSession(ctx context.Context, data *webauthn.SessionData) error

func DeleteSessionByUserID

func DeleteSessionByUserID(userID uint, id uuid.UUID) func(tx *gorm.DB) error

func LoginUser

func LoginUser(ctx context.Context, opt LoginOpt) error

func MarshalCredentialCreation

func MarshalCredentialCreation(c protocol.CredentialCreation) graphql.Marshaler

func UnmarshalCredentialAssertion

func UnmarshalCredentialAssertion(v interface{}) (protocol.CredentialAssertion, error)

func UnmarshalCredentialCreation

func UnmarshalCredentialCreation(v interface{}) (protocol.CredentialCreation, error)

Types

type AuthSession

type AuthSession struct {
	ID        uuid.UUID `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	Data      datatypes.JSONType[webauthn.SessionData]
}

func FirstAuthSession

func FirstAuthSession(ctx context.Context) (*AuthSession, error)

func (AuthSession) Value

func (a AuthSession) Value() webauthn.SessionData

type Credential

type Credential struct {
	gorm.Model
	UserID      uint
	User        User
	Description string
	LastLogin   *time.Time
	Data        webauthn.Credential `gorm:"serializer:json"`
}

func CredentialByUserID

func CredentialByUserID(db *gorm.DB, userID uint, id string) (*Credential, error)

type LoginOpt

type LoginOpt struct {
	UserID     *uint
	Credential *Credential
	Tx         *gorm.DB
}

type Session

type Session struct {
	ID        uuid.UUID `gorm:"primarykey"`
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
	UserID    uint
	User      User
}

func AllSessionByUserID

func AllSessionByUserID(tx *gorm.DB, userID uint) ([]*Session, error)

func (*Session) IsActive

func (s *Session) IsActive() bool

func (*Session) IsCurrent

func (s *Session) IsCurrent(ctx context.Context) bool

func (*Session) String

func (s *Session) String() string

type User

type User struct {
	gorm.Model
	// `RANDOM_BYTES` was added with MariaDB 10.10.0
	// AuthnID     []byte `gorm:"type:BLOB(16);default:RANDOM_BYTES(16);not null"`
	AuthnID     []byte `gorm:"type:BLOB(16)"`
	Name        string `gorm:"type:VARCHAR(255);not null"`
	DisplayName string `gorm:"type:VARCHAR(255);not null"`
	Credentials []Credential
}

func CreateUser

func CreateUser(ctx context.Context, name string) (*User, error)

func FirstUser

func FirstUser(ctx context.Context) (*User, error)

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

func (*User) IDStr

func (u *User) IDStr() string

func (User) WebAuthnCredentials

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

func (User) WebAuthnDisplayName

func (u User) WebAuthnDisplayName() string

func (User) WebAuthnID

func (u User) WebAuthnID() []byte

func (User) WebAuthnIcon

func (u User) WebAuthnIcon() string

func (User) WebAuthnName

func (u User) WebAuthnName() string

Jump to

Keyboard shortcuts

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