Documentation
¶
Overview ¶
Package sqlite implements gouncer's user and session persistence in SQLite tables of its own.
Index ¶
- func Migrate(ctx context.Context, db *sql.DB, opts MigrateOptions) error
- type MigrateOptions
- type UserStore
- func (s *UserStore) ActivateByToken(ctx context.Context, tokenHash []byte, now time.Time, passwordHash string) (uuid.UUID, error)
- func (s *UserStore) CreateFirstUser(ctx context.Context, u gouncer.User) error
- func (s *UserStore) CreateSession(ctx context.Context, session gouncer.Session) error
- func (s *UserStore) CreateToken(ctx context.Context, t gouncer.Token, live int) error
- func (s *UserStore) CreateUser(ctx context.Context, u gouncer.User) error
- func (s *UserStore) DeleteExpiredSessions(ctx context.Context, now time.Time) (int64, error)
- func (s *UserStore) DeleteExpiredTokens(ctx context.Context, now time.Time) (int64, error)
- func (s *UserStore) DeleteSession(ctx context.Context, tokenHash []byte) error
- func (s *UserStore) GrantRoleToRoleless(ctx context.Context, role string) (int64, error)
- func (s *UserStore) HasUsers(ctx context.Context) (bool, error)
- func (s *UserStore) ListUsers(ctx context.Context) ([]gouncer.User, error)
- func (s *UserStore) ReplaceToken(ctx context.Context, t gouncer.Token) error
- func (s *UserStore) ResetByToken(ctx context.Context, tokenHash []byte, now time.Time, passwordHash string) (uuid.UUID, error)
- func (s *UserStore) SetUserDisabled(ctx context.Context, id uuid.UUID, disabled bool) error
- func (s *UserStore) SetUserDisabledFrom(ctx context.Context, id uuid.UUID, held string, disabled bool, ...) error
- func (s *UserStore) SetUserDisabledUnderCover(ctx context.Context, id uuid.UUID, disabled bool, privileged gouncer.Roles) error
- func (s *UserStore) SetUserRole(ctx context.Context, id uuid.UUID, role string, privileged gouncer.Roles) error
- func (s *UserStore) SetUserRoleFrom(ctx context.Context, id uuid.UUID, held, role string, privileged gouncer.Roles) error
- func (s *UserStore) UserByEmail(ctx context.Context, email string) (gouncer.User, error)
- func (s *UserStore) UserByID(ctx context.Context, id uuid.UUID) (gouncer.User, error)
- func (s *UserStore) UserBySession(ctx context.Context, tokenHash []byte, now time.Time) (gouncer.User, error)
- func (s *UserStore) UsersByIDs(ctx context.Context, ids []uuid.UUID) ([]gouncer.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type MigrateOptions ¶
type MigrateOptions struct {
// LockWait is how long a run waits for the migration lock, above zero.
LockWait time.Duration
// LockPoll is how often a waiting run tries the migration lock, above zero.
LockPoll time.Duration
}
MigrateOptions sets how a run of Migrate waits for the migration lock of the database file.
type UserStore ¶
type UserStore struct {
// contains filtered or unexported fields
}
UserStore persists users, their sessions and their tokens in the auth tables of an application's SQLite file.
func NewUserStore ¶
NewUserStore returns a UserStore on the handle dbkit/sqlite opened for the application.
func (*UserStore) ActivateByToken ¶
func (s *UserStore) ActivateByToken( ctx context.Context, tokenHash []byte, now time.Time, passwordHash string, ) (uuid.UUID, error)
ActivateByToken spends the invite token, stores the password hash and confirms the account it names.
func (*UserStore) CreateFirstUser ¶ added in v0.3.0
CreateFirstUser stores u while the store holds no account, or answers authkit.ErrSetupDone and stores nothing.
func (*UserStore) CreateSession ¶
CreateSession stores a login session.
func (*UserStore) CreateToken ¶
CreateToken stores t for an enabled account while fewer than live unexpired tokens stand for its purpose.
func (*UserStore) CreateUser ¶
CreateUser stores a new user, or answers gouncer.ErrEmailTaken when the email is already in use.
func (*UserStore) DeleteExpiredSessions ¶
DeleteExpiredSessions removes the sessions that expired at or before now and returns how many it removed.
func (*UserStore) DeleteExpiredTokens ¶
DeleteExpiredTokens removes the expired tokens and the unconfirmed accounts an expired invite leaves behind.
func (*UserStore) DeleteSession ¶
DeleteSession removes the session with the token hash, if any.
func (*UserStore) GrantRoleToRoleless ¶
GrantRoleToRoleless gives a role to every account holding none, reporting how many took it.
func (*UserStore) HasUsers ¶ added in v0.3.0
HasUsers reports whether the store holds any account, disabled and unconfirmed ones included.
func (*UserStore) ListUsers ¶
ListUsers returns every user ordered by name regardless of ASCII case, then by id, without password hashes.
func (*UserStore) ReplaceToken ¶
ReplaceToken stores t for an enabled account in place of every token it holds for the same purpose.
func (*UserStore) ResetByToken ¶
func (s *UserStore) ResetByToken( ctx context.Context, tokenHash []byte, now time.Time, passwordHash string, ) (uuid.UUID, error)
ResetByToken spends the reset token, stores the password hash and ends every session of the account it names.
func (*UserStore) SetUserDisabled ¶
SetUserDisabled writes whether the user may log in, ending its sessions and tokens on a disable.
func (*UserStore) SetUserDisabledFrom ¶
func (s *UserStore) SetUserDisabledFrom( ctx context.Context, id uuid.UUID, held string, disabled bool, privileged gouncer.Roles, ) error
SetUserDisabledFrom disables an account still holding held, refusing to leave no enabled account privileged.
func (*UserStore) SetUserDisabledUnderCover ¶
func (s *UserStore) SetUserDisabledUnderCover( ctx context.Context, id uuid.UUID, disabled bool, privileged gouncer.Roles, ) error
SetUserDisabledUnderCover disables an account, refusing to leave no enabled account privileged.
func (*UserStore) SetUserRole ¶
func (s *UserStore) SetUserRole(ctx context.Context, id uuid.UUID, role string, privileged gouncer.Roles) error
SetUserRole writes an account's role, refusing to leave no enabled account under a privileged one.
func (*UserStore) SetUserRoleFrom ¶
func (s *UserStore) SetUserRoleFrom( ctx context.Context, id uuid.UUID, held, role string, privileged gouncer.Roles, ) error
SetUserRoleFrom writes the role of an account still holding held, refusing to leave no enabled account privileged.
func (*UserStore) UserByEmail ¶
UserByEmail returns the user owning the email, or gouncer.ErrUserNotFound when none does.
func (*UserStore) UserByID ¶
UserByID returns the user with the id, disabled or not, or gouncer.ErrUserNotFound.