authz

package
v0.0.0-...-389a847 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2016 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package authz provides login requirement wrappers for HTTP handlers.

The following session variables are used:

"user_id": int.
If not set or zero, not logged in.

"must_change_password": bool.
If set to true, redirect all requests with a path other than
ChangePasswordPath to ChangePasswordPath.

"user_is_admin": bool.
Used for MustAdmin. A user is considered to be an admin
if this is set to true.

Index

Constants

This section is empty.

Variables

View Source
var (
	// The only URL path which can be loaded if "must_change_password" is set.
	// Requests for all other paths redirect to this.
	ChangePasswordPath = "/auth/chpw"

	// Relative or absolute URL to redirect to if login is required.
	LoginURL = "/auth/login"

	// Relative or absolute URL to redirect to after login if there is no
	// specific page to return to.
	AfterLoginURL = "/"
)

Functions

func MustAdmin

func MustAdmin(h, notFound http.Handler) http.Handler

Ensures that "user_is_admin" is set to true.

func MustLogin

func MustLogin(h http.Handler) http.Handler

Redirects to LoginURL unless session value "user_id" is a nonzero integer.

If "must_change_password" is set to true, any request for a path other than ChangePasswordPath is redirected to that path.

func MustLoginFunc

func MustLoginFunc(h func(rw http.ResponseWriter, req *http.Request)) http.Handler

Like MustLogin, but takes a function as the wrapped handler.

func MustNotLogin

func MustNotLogin(h http.Handler) http.Handler

Ensures that a user is not logged in. Session value "user_id" must be absent or zero. If a user is logged in, redirects to AfterLoginURL.

func MustNotLoginFunc

func MustNotLoginFunc(h func(rw http.ResponseWriter, req *http.Request)) http.Handler

Like MustNotLogin, but takes a function as the wrapped handler.

func RedirectWithReturn

func RedirectWithReturn(req *http.Request, statusCode int, targetURL string)

Redirect to a given URL with the given status code, such that the user agent can eventually be redirected back to the current URL, unless a return URL has already been provided in the current request, in which case that return URL is used.

func ReturnRedirect

func ReturnRedirect(req *http.Request, statusCode int, defaultURL string)

Redirect back to a return URL, if specified; otherwise, redirect to defaultURL.

Types

This section is empty.

Jump to

Keyboard shortcuts

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