store

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrDuplicateEmail     = errors.New("email already exists")
	ErrLastAdmin          = errors.New("cannot remove the last admin")
)

Functions

func ParseHostsText

func ParseHostsText(text string) []string

Types

type LoginPending

type LoginPending struct {
	UserID   int64
	Remember bool
}

type Role

type Role string
const (
	RoleAdmin Role = "admin"
	RoleUser  Role = "user"
)

func ParseRole

func ParseRole(s string) (Role, error)

type Store

type Store struct {
	// contains filtered or unexported fields
}

func Open

func Open(path string) (*Store, error)

func (*Store) CanAccessHost

func (s *Store) CanAccessHost(ctx context.Context, user User, host string) (bool, error)

func (*Store) ClearUserTOTP

func (s *Store) ClearUserTOTP(ctx context.Context, userID int64) error

func (*Store) Close

func (s *Store) Close() error

func (*Store) ConsumeLoginPending

func (s *Store) ConsumeLoginPending(ctx context.Context, id string) (LoginPending, error)

func (*Store) ConsumeTOTPSetupPending

func (s *Store) ConsumeTOTPSetupPending(ctx context.Context, userID int64) (string, error)

func (*Store) CountAdmins

func (s *Store) CountAdmins(ctx context.Context) (int, error)

func (*Store) CountUsers

func (s *Store) CountUsers(ctx context.Context) (int, error)

func (*Store) CreateLoginPending

func (s *Store) CreateLoginPending(ctx context.Context, id string, userID int64, remember bool, expires time.Time) error

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, id string, userID int64, expires time.Time) error

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, email, passwordHash string, role Role) (int64, error)

func (*Store) DeleteLoginPending

func (s *Store) DeleteLoginPending(ctx context.Context, id string) error

func (*Store) DeleteSession

func (s *Store) DeleteSession(ctx context.Context, id string) error

func (*Store) DeleteTOTPSetupPending

func (s *Store) DeleteTOTPSetupPending(ctx context.Context, userID int64) error

func (*Store) DeleteUser

func (s *Store) DeleteUser(ctx context.Context, id int64) error

func (*Store) DeleteUserSessions

func (s *Store) DeleteUserSessions(ctx context.Context, userID int64) error

func (*Store) ListDistinctHosts

func (s *Store) ListDistinctHosts(ctx context.Context) ([]string, error)

func (*Store) ListUsers

func (s *Store) ListUsers(ctx context.Context) ([]User, error)

func (*Store) ListUsersWithHosts

func (s *Store) ListUsersWithHosts(ctx context.Context) ([]UserWithHosts, error)

func (*Store) LoginPendingByID

func (s *Store) LoginPendingByID(ctx context.Context, id string) (LoginPending, error)

func (*Store) PeekTOTPSetupPending

func (s *Store) PeekTOTPSetupPending(ctx context.Context, userID int64) (secret string, ok bool, err error)

func (*Store) PingContext added in v0.3.1

func (s *Store) PingContext(ctx context.Context) error

func (*Store) SaveTOTPSetupPending

func (s *Store) SaveTOTPSetupPending(ctx context.Context, userID int64, secret string, expires time.Time) error

func (*Store) SessionUserID

func (s *Store) SessionUserID(ctx context.Context, id string) (int64, error)

func (*Store) SetUserHosts

func (s *Store) SetUserHosts(ctx context.Context, userID int64, hosts []string) error

func (*Store) SetUserTOTPSecret

func (s *Store) SetUserTOTPSecret(ctx context.Context, userID int64, secret string) error

func (*Store) UpdateUserPassword

func (s *Store) UpdateUserPassword(ctx context.Context, id int64, passwordHash string) error

func (*Store) UpdateUserRole

func (s *Store) UpdateUserRole(ctx context.Context, id int64, role Role) error

func (*Store) UserByEmail

func (s *Store) UserByEmail(ctx context.Context, email string) (User, string, error)

func (*Store) UserByID

func (s *Store) UserByID(ctx context.Context, id int64) (User, error)

func (*Store) UserHosts

func (s *Store) UserHosts(ctx context.Context, userID int64) ([]string, error)

func (*Store) UserTOTPEnabled

func (s *Store) UserTOTPEnabled(ctx context.Context, userID int64) (bool, error)

func (*Store) UserTOTPSecret

func (s *Store) UserTOTPSecret(ctx context.Context, userID int64) (string, error)

type User

type User struct {
	ID        int64
	Email     string
	Role      Role
	CreatedAt time.Time
}

type UserWithHosts

type UserWithHosts struct {
	User
	Hosts       []string
	TOTPEnabled bool
}

Jump to

Keyboard shortcuts

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