auth

package
v0.1.0-alpha.16 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UserContextKey contextKey = "user"
)

Variables

View Source
var (
	ErrUserNotFound        = errors.New("user not found")
	ErrWrongUserOrPassword = errors.New("wrong user or password")

	ErrInvalidUsername = errors.New("invalid username")
	ErrShortUsername   = errors.New("short username")
	ErrLongUsername    = errors.New("long username")

	ErrInvalidPassword          = errors.New("invalid password")
	ErrShortPassword            = errors.New("short password")
	ErrLongPassword             = errors.New("long password")
	ErrCurrentPasswordIncorrect = errors.New("current password is incorrect")
)

Functions

This section is empty.

Types

type AuthenticationMiddleware

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

func NewAuthenticationMiddleware

func NewAuthenticationMiddleware(userService userService) *AuthenticationMiddleware

func (*AuthenticationMiddleware) Wrap

type ChangePasswordHandler

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

func NewChangePasswordHandler

func NewChangePasswordHandler(service *Service) *ChangePasswordHandler

func (*ChangePasswordHandler) ServeHTTP

type DeleteHandler

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

func NewDeleteHandler

func NewDeleteHandler(service userDeleter) *DeleteHandler

func (*DeleteHandler) ServeHTTP

func (h *DeleteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Domain

type Domain struct {
	Repository  *Repository
	Service     *Service
	HandleGroup *httpserver.HandlerGroup
	Middleware  httpserver.Middleware
}

func New

func New(db db, authStorage authStorage, sessionCookieName string, usernameValidator, passwordValidator func(string) error, cleanupEnqueuer cleanupEnqueuer) *Domain

func (*Domain) GetRepository

func (d *Domain) GetRepository() any

type GetHandler

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

func NewGetHandler

func NewGetHandler(service *Service) *GetHandler

func (*GetHandler) ServeHTTP

func (h *GetHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LoginHandler

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

func NewLoginHandler

func NewLoginHandler(service *Service) *LoginHandler

func (*LoginHandler) ServeHTTP

func (h *LoginHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type LogoutHandler

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

func NewLogoutHandler

func NewLogoutHandler(service *Service) *LogoutHandler

func (*LogoutHandler) ServeHTTP

func (h *LogoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type RegisterHandler

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

func NewRegisterHandler

func NewRegisterHandler(service *Service) *RegisterHandler

func (*RegisterHandler) ServeHTTP

func (h *RegisterHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type Repository

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

func NewRepository

func NewRepository(db db) *Repository

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, user *User) error

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, id string) error

func (*Repository) Get

func (r *Repository) Get(ctx context.Context, id string) (*User, error)

func (*Repository) GetByUsername

func (r *Repository) GetByUsername(ctx context.Context, username string) (*User, error)

func (*Repository) Migrations

func (r *Repository) Migrations() []database.Migration

func (*Repository) UpdatePassword

func (r *Repository) UpdatePassword(ctx context.Context, id, password, salt string) error

type Service

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

func NewService

func NewService(repo repository, authStorage authStorage, sessionCookieName string, usernameValidator, passwordValidator func(string) error, cleanupEnqueuer cleanupEnqueuer) *Service

func (*Service) ChangePassword

func (s *Service) ChangePassword(ctx context.Context, currentPassword, newPassword string) error

func (*Service) CookieName

func (s *Service) CookieName() string

func (*Service) CreateSessionFromUsernameAndPassword

func (s *Service) CreateSessionFromUsernameAndPassword(ctx context.Context, username, password string) (string, error)

func (*Service) CreateWithLoginAndPassword

func (s *Service) CreateWithLoginAndPassword(ctx context.Context, username, password string) error

func (*Service) DeleteSession

func (s *Service) DeleteSession(ctx context.Context, sessionId string) error

func (*Service) DeleteUser

func (s *Service) DeleteUser(ctx context.Context) error

func (*Service) Get

func (s *Service) Get(ctx context.Context, id string) (*User, error)

func (*Service) GetFromSession

func (s *Service) GetFromSession(ctx context.Context, sessionId string) (*User, error)

type Status

type Status string
const (
	StatusActive   Status = "active"
	StatusInactive Status = "inactive"
	StatusDeleted  Status = "deleted"
)

type User

type User struct {
	ID       string    `db:"id"       json:"id"`
	Username string    `db:"username" json:"username"`
	Password string    `db:"password" json:"password"`
	Salt     string    `db:"salt"     json:"salt"`
	Created  time.Time `db:"created"  json:"created"`
	Updated  time.Time `db:"updated"  json:"updated"`
	Status   Status    `db:"status"   json:"status"`
}

func UserFromContext

func UserFromContext(ctx context.Context) *User

type UserCleanupJob

type UserCleanupJob struct {
	UserID    string
	DeletedAt time.Time
}

UserCleanupJob represents a cleanup job that is enqueued after a user is deleted. It contains the necessary information for cleanup handlers to identify and process the cleanup tasks associated with the deleted user.

Jump to

Keyboard shortcuts

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