auth

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: GPL-3.0 Imports: 21 Imported by: 0

Documentation

Overview

templ: version: v0.2.513

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateMiddleware

func CreateMiddleware(service Service) func(next http.Handler) http.Handler

func GetUser

func GetUser(r *http.Request) *models.User

func RequiredMiddleware

func RequiredMiddleware(next http.Handler) http.Handler

Types

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

func New

func New(repository Repository, conf *config.Config, log *slog.Logger) *Auth

func (*Auth) Authenticate

func (a *Auth) Authenticate(ctx context.Context, username, password string) (*models.User, error)

func (*Auth) CreateSession

func (a *Auth) CreateSession(user *models.User) (*models.Session, error)

func (*Auth) CreateUser

func (a *Auth) CreateUser(ctx context.Context, username, password string) (*models.User, error)

func (*Auth) Mount

func (a *Auth) Mount(router chi.Router)

func (*Auth) ValidateSession

func (a *Auth) ValidateSession(session *models.Session) error

type Repository

type Repository interface {
	GetByUsername(ctx context.Context, username string) (*models.UserCredentials, error)
	Insert(ctx context.Context, username, password, salt string) (*models.UserCredentials, error)
}

type RepositoryImpl

type RepositoryImpl struct {
	// contains filtered or unexported fields
}

func NewRepository

func NewRepository(db *sqlx.DB) *RepositoryImpl

func (*RepositoryImpl) GetByUsername

func (r *RepositoryImpl) GetByUsername(ctx context.Context, username string) (*models.UserCredentials, error)

func (*RepositoryImpl) Insert

func (r *RepositoryImpl) Insert(ctx context.Context, username, password, salt string) (*models.UserCredentials, error)

type Service

type Service interface {
	ValidateSession(session *models.Session) error
}

Jump to

Keyboard shortcuts

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