login

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultFormHandler is used to display the login form if no custom one is used.
	DefaultFormHandler http.Handler

	// DefaultErrorHandler is used to display login errors if no custom handler is used.
	DefaultErrorHandler http.Handler

	// DefaultRegisterFormHandler is used to display the registration form if no custom one is used.
	DefaultRegisterFormHandler http.Handler

	// DefaultRegisterErrorHandler is used to display registration errors if no custom one is used.
	DefaultRegisterErrorHandler http.Handler
)

Functions

This section is empty.

Types

type Auther

type Auther interface {
	Auth(username, password string) (bool, error)
}

type ErrorHandler

type ErrorHandler interface {
	ServeHTTPError(http.ResponseWriter, *http.Request, error)
}

ErrorHandler is a http.Handler which is interested in errors.

type Exempter

type Exempter interface {
	// Exempt checks a request, returning true if it is exempt from login checking.
	Exempt(*http.Request) bool
}

Exempter can be implemented by handlers to allow for skipping login checks for certain requests.

type Handler

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

Handler performs login checking.

func NewHandler

func NewHandler(auther Auther, next http.Handler, secret []byte, duration time.Duration, loginFormHandler, loginErrorHandler, registerFormHandler, registerErrorHandler http.Handler, hash crypto.Hash) (*Handler, error)

NewHandler initializes a Handler for use.

dsn is the data source name (https://github.com/mattn/go-sqlite3#connection-string) of the sqlite database where logins are stored.

next is the Handler whose ServeHTTP method is called for valid sessions.

secret is used to verify cookie authenticity.

duration specifies how long a session should be valid.

loginFormHandler, loginErrorHandler, registerFormHandler and registerErrorHandler are handlers used to display login and registration pages. loginFormHandler should post a form with "username" and "password" fields to "/login", registrationFormHandler should post a form with "username", "password" and "passwordAgain" fields to "/register". for testing purposes or if styling doesn't matter, the Default* Handlers defined in this package can be used.

hash is a cryptographic hash to use for cookie authenticity.

func (*Handler) ServeHTTP

func (l *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP performs login, logout or session checking.

type Registerer

type Registerer interface {
	Register(username, password string) error
}

type SQliteAuther

type SQliteAuther struct {
	*sql.DB
}

func NewSQliteAuther

func NewSQliteAuther(db *sql.DB) SQliteAuther

func (SQliteAuther) Auth

func (s SQliteAuther) Auth(username, password string) (bool, error)

func (SQliteAuther) Register

func (s SQliteAuther) Register(username, password string) error

type UsernameHandler

type UsernameHandler interface {
	ServeHTTPUsername(http.ResponseWriter, *http.Request, string)
}

UsernameHandler is a http.Handler which is interested in the currently logged in user.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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