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
- func AddMembership(ctx context.Context, q pgdb.Queryer, acctID uuid.UUID, group string) error
- func CreateGroups(ctx context.Context, q pgdb.Queryer, groups []string) error
- func Delete(ctx context.Context, q pgdb.Queryer, id uuid.UUID) error
- func DeleteGroups(ctx context.Context, q pgdb.Queryer, groups []string) error
- func Groups(ctx context.Context, q pgdb.Queryer) ([]string, error)
- func RegisterMigrations(mig *migrate.Migrator) error
- func RemoveMembership(ctx context.Context, q pgdb.Queryer, acctID uuid.UUID, group string) error
- func SetMembership(ctx context.Context, btx pgdb.BeginTxer, acctID uuid.UUID, groups []string) error
- type Account
Constants ¶
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 ¶
AddMembership adds the specified group to the membership of the account, if necessary. Note that non-existing groups are silently ignored.
func CreateGroups ¶
CreateGroups ensures the specified groups are created if they do not already exist.
func DeleteGroups ¶
DeleteGroups deletes the specified groups. Non-existing groups are ignored.
func RegisterMigrations ¶
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 ¶
RemoveMembership removes the specified group from the membership of the account, if necessary. 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 ¶
ByEmail returns the account corresponding to the email. If none exist, the error is sql.ErrNoRows (check with errors.Is).
func ByID ¶
ByID returns the account corresponding to the primary key identifier. If none exist, the error is sql.ErrNoRows (check with errors.Is).
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. |