auth

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2023 License: BSD-3-Clause Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")
View Source
var ErrLocalAuthUserNotFound = errors.New("user for local auth not found")
View Source
var ErrPasswordEmpty = errors.New("password must not be empty")
View Source
var ErrUserNotFound = errors.New("user not found")
View Source
var ErrUsernameEmpty = errors.New("username must not be empty")

Functions

func NewDecoder

func NewDecoder() *form.Decoder

Types

type Argon2Params

type Argon2Params struct {
	KeyLen  uint32 `json:"keyLen"`
	Memory  uint32 `json:"memory"`
	Threads uint8  `json:"threads"`
	Time    uint32 `json:"time"`
	Version int    `json:"version"`
}

type Control

type Control struct {
	DB            *database.Database
	UserRepo      UserRepo
	LocalAuthRepo LocalAuthRepo
	Argon2Params  Argon2Params
}

func (*Control) RunInitSetup

func (c *Control) RunInitSetup(ctx context.Context, username string, plaintextPasswd string) error

type CurrentUserPageViewModel

type CurrentUserPageViewModel struct {
	User           *User
	ValidationErrs map[string]string
}

type DeleteUserPageViewModel

type DeleteUserPageViewModel struct {
	User *User
}

type ListUsersPageViewModel

type ListUsersPageViewModel struct {
	Page    *UserListPage
	Query   ListUsersQuery
	Compact bool
}

type ListUsersQuery

type ListUsersQuery struct {
	Search   string
	Page     int
	PageSize int
	OrderBy  string
	OrderDir string
}

type LocalAuthRepo

type LocalAuthRepo interface {
	GetLocalUser(ctx context.Context, tx bob.Executor, username string) (*LocalAuthUser, error)
	CreateLocalUser(ctx context.Context, tx bob.Executor, user *LocalAuthUser) (*LocalAuthUser, error)
	UpdateLocalUser(ctx context.Context, tx bob.Executor, user *LocalAuthUser) error
	DeleteByUsername(ctx context.Context, tx bob.Executor, username string) error
}

type LocalAuthRepoSQLite

type LocalAuthRepoSQLite struct{}

func (*LocalAuthRepoSQLite) CreateLocalUser

func (*LocalAuthRepoSQLite) CreateLocalUser(ctx context.Context, tx bob.Executor, user *LocalAuthUser) (*LocalAuthUser, error)

func (*LocalAuthRepoSQLite) DeleteByUsername

func (*LocalAuthRepoSQLite) DeleteByUsername(ctx context.Context, tx bob.Executor, username string) error

func (*LocalAuthRepoSQLite) GetLocalUser

func (*LocalAuthRepoSQLite) GetLocalUser(ctx context.Context, tx bob.Executor, username string) (*LocalAuthUser, error)

func (*LocalAuthRepoSQLite) UpdateLocalUser

func (*LocalAuthRepoSQLite) UpdateLocalUser(ctx context.Context, tx bob.Executor, user *LocalAuthUser) error

type LocalAuthUser

type LocalAuthUser struct {
	ID                     int64
	Username               string
	Algorithm              string
	Params                 string
	Salt                   []byte
	Password               []byte
	RequiresPasswordChange bool
	CreatedAt              time.Time
	UpdatedAt              time.Time
}

type NewUserPageViewModel

type NewUserPageViewModel struct {
	User           *User
	ValidationErrs map[string]string
}

type ResetPasswordPageViewModel

type ResetPasswordPageViewModel struct {
	ValidationErrs map[string]string
}

type UIRouter

type UIRouter struct {
	Control *Control
	Decoder *form.Decoder
}

func (*UIRouter) RegisterRoutes

func (rt *UIRouter) RegisterRoutes(mux *chi.Mux)

type User

type User struct {
	ID       int64  `form:"-"`
	Username string `form:"username"`

	DisplayName string `form:"display_name"`
	IsAdmin     bool   `form:"is_admin"`

	RequiresPasswordChange bool `form:"-"`

	AuthRef string `form:"-"`

	CreatedAt time.Time `form:"-"`
	UpdatedAt time.Time `form:"-"`
}

type UserListPage

type UserListPage struct {
	Users    []*User
	Total    int
	NumPages int
	Page     int
	PageSize int
}

type UserRepo

type UserRepo interface {
	List(ctx context.Context, exec bob.Executor, query ListUsersQuery) (*UserListPage, error)
	Create(ctx context.Context, tx bob.Executor, toCreate *User) (*User, error)
	Update(ctx context.Context, tx bob.Executor, toUpdate *User) (*User, error)
	Get(ctx context.Context, tx bob.Executor, id int64) (*User, error)
	GetByRef(ctx context.Context, tx bob.Executor, ref string) (*User, error)
	CountAdmins(ctx context.Context, tx bob.Executor) (int64, error)
	Delete(ctx context.Context, tx bob.Executor, id int64) error
}

type UserRepoSQLite

type UserRepoSQLite struct{}

func (*UserRepoSQLite) CountAdmins

func (*UserRepoSQLite) CountAdmins(ctx context.Context, tx bob.Executor) (int64, error)

func (*UserRepoSQLite) Create

func (*UserRepoSQLite) Create(ctx context.Context, tx bob.Executor, toCreate *User) (*User, error)

func (*UserRepoSQLite) Delete

func (*UserRepoSQLite) Delete(ctx context.Context, tx bob.Executor, id int64) error

func (*UserRepoSQLite) Get

func (*UserRepoSQLite) Get(ctx context.Context, tx bob.Executor, id int64) (*User, error)

func (*UserRepoSQLite) GetByRef

func (*UserRepoSQLite) GetByRef(ctx context.Context, tx bob.Executor, ref string) (*User, error)

func (*UserRepoSQLite) List

func (*UserRepoSQLite) Update

func (*UserRepoSQLite) Update(ctx context.Context, tx bob.Executor, toUpdate *User) (*User, error)

Jump to

Keyboard shortcuts

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