database

package
v0.0.0-...-692b37b Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2022 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Database dialects
	DialectMySQL     = "mysql"
	DialectPostgres  = "prostgres"
	DialectSqlite3   = "sqlite3"
	DialectSqlServer = "sqlserver"
)

Variables

View Source
var (
	// Errors
	ErrUserExists = errors.New("The username, email or phone number already exists")
)

Functions

This section is empty.

Types

type Database

type Database interface {
	// GetUser returns the user for the given user ID. This ID is not to be
	// confused with the records ID in the table but the generated value for the
	// user_id field.
	GetUser(id string) (models.User, error)

	// GetUserByName returns the user for the given name. This name can be
	// either the username or email address of the user as an identifier.
	GetUserByName(name string) (models.User, error)

	// SaveUser adds the given user to the database. It should fill in the
	// remaining fields like the record and user ID.
	SaveUser(user models.User) (models.User, error)

	// SetPublicKey updates the user for the given user ID and sets the user's
	// public key.
	SetPublicKey(userId, pubKey string) error

	// UpdateTotp updates the TOTP state of the user for the given user ID.
	// Either enabling TOTP and/or setting its value itself.
	UpdateTotp(enable bool, totp, userId string) error

	// UpdateTokens updates the user's access and refresh token for the given
	// user ID.
	UpdateTokens(token, refreshToken, userId string) error
}

Database represents an interface to the authentication database and the management of users.

func New

func New(ctx context.Context, dialect, path string) (Database, error)

New returns a new authentication database for the context, dialect, and URI path to the database. For accepted dialects see the Dialect* constants, E.g. DialectPostgres.

Jump to

Keyboard shortcuts

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