accounts

package
v0.0.0-...-d4212fa Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package accounts provides a substantial implementation of the security-sensitive and often subtle flows related to accounts: registration and deletion, login and logout, reset password, verify and change email, and a simple group-based authorization mechanism.

Index

Constants

View Source
const AccountsTag = errors.ErrorTag("accounts")

AccountsTag is the error tag used to tag validation errors in this package. Untagged errors are typically internal server errors in HTTP vocabulary.

Variables

This section is empty.

Functions

func AddMembership

func AddMembership(ctx context.Context, q pgdb.Queryer, acctID uuid.UUID, group string) error

AddMembership adds the specified group to the membership of the account, if necessary. Note that non-existing groups are silently ignored.

func CreateGroups

func CreateGroups(ctx context.Context, q pgdb.Queryer, groups []string) error

CreateGroups ensures the specified groups are created if they do not already exist.

func Delete

func Delete(ctx context.Context, q pgdb.Queryer, id uuid.UUID) error

Delete deletes the account identified by the primary key id.

func DeleteGroups

func DeleteGroups(ctx context.Context, q pgdb.Queryer, groups []string) error

DeleteGroups deletes the specified groups. Non-existing groups are ignored.

func Groups

func Groups(ctx context.Context, q pgdb.Queryer) ([]string, error)

Groups returns the list of existing group names.

func RegisterMigrations

func RegisterMigrations(mig *migrate.Migrator) error

RegisterMigrations registers the accounts package's migrations with the provided migrator. The migrations are registered under the group "karbur/accounts" and depends on "karbur/tokens".

func RemoveMembership

func RemoveMembership(ctx context.Context, q pgdb.Queryer, acctID uuid.UUID, group string) error

RemoveMembership removes the specified group from the membership of the account, if necessary. Note that non-existing groups are silently ignored.

func SetMembership

func SetMembership(ctx context.Context, btx pgdb.BeginTxer, acctID uuid.UUID, groups []string) error

SetMembership sets the account's group membership to exactly the provided groups. Note that non-existing groups are silently ignored.

Types

type Account

type Account struct {
	ID       uuid.UUID           `db:"id"`
	Email    string              `db:"email"`
	Password string              `db:"password"`
	Verified sql.Null[time.Time] `db:"verified"`
	Created  time.Time           `db:"created"`
	Groups   []string            `db:"groups"`
}

Account represents a database account. If its email is verified, the Verified field is not null (Verified.Valid is true), otherwise it is yet to be verified.

func ByEmail

func ByEmail(ctx context.Context, q pgdb.Queryer, email string) (*Account, error)

ByEmail returns the account corresponding to the email. If none exist, the error is sql.ErrNoRows (check with errors.Is).

func ByID

func ByID(ctx context.Context, q pgdb.Queryer, id uuid.UUID) (*Account, error)

ByID returns the account corresponding to the primary key identifier. If none exist, the error is sql.ErrNoRows (check with errors.Is).

func Create

func Create(ctx context.Context, q pgdb.Queryer, email, hashedPwd string) (*Account, error)

Create creates a new account with the provided email and hashed password. It returns a properly-tagged error if database validations fail (such as account already existing or email or password length error).

Directories

Path Synopsis
Package acctctx provides type-safe access to account-related values stored in the context.
Package acctctx provides type-safe access to account-related values stored in the context.
Package acctmw provides a substantial implementation of the security-sensitive and often subtle flows related to accounts: registration and deletion, login and logout, reset password, verify and change email, and a simple group-based authorization mechanism.
Package acctmw provides a substantial implementation of the security-sensitive and often subtle flows related to accounts: registration and deletion, login and logout, reset password, verify and change email, and a simple group-based authorization mechanism.

Jump to

Keyboard shortcuts

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