Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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 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.
type SQliteAuther ¶
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