frontend

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2022 License: GPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HTTPHandler

func HTTPHandler(engine core.Engine, isBehindTLSProxy bool) http.Handler

HTTPHandler returns the main http.Handler.

func LoadSession

func LoadSession(i *Interaction)

LoadSession is a handler step that loads the session or starts a new one if there is no valid session.

func ReadFormStateFromRequest

func ReadFormStateFromRequest(i *Interaction)

ReadFormStateFromRequest is a handler step that initializes i.FormState from the incoming request. This is only suitable for POST handlers.

func SaveSession

func SaveSession(i *Interaction)

SaveSession is a handler step that calls Interaction.SaveSession.

func UseEmptyFormState

func UseEmptyFormState(i *Interaction)

UseEmptyFormState is a handler step that initializes an empty i.FormState.

Types

type Flash

type Flash struct {
	Type    string //either "danger" or "success"
	Message string
}

Flash is a flash message.

type Handler

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

Handler allows to construct HTTP handlers by chained method calls describing the sequence of actions taken.

func Do

func Do(steps ...HandlerStep) Handler

Do creates a Handler with the given steps.

func (Handler) ServeHTTP

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

ServeHTTP implements the http.Handler interface.

type HandlerStep

type HandlerStep func(i *Interaction)

HandlerStep is a single step executed by a handler. When a handler step renders a result, it shall set i.Writer = nil to ensure that the remaining steps do not get executed.

func RedirectTo

func RedirectTo(url string) HandlerStep

RedirectTo is a handler step that always redirects to the given URL.

func ShowForm

func ShowForm(title string) HandlerStep

ShowForm is a final handler step that renders i.FormSpec with i.FormState.

func ShowFormIfErrors

func ShowFormIfErrors(title string) HandlerStep

ShowFormIfErrors is like ShowForm, but only renders an output if i.FormState is not valid.

func ShowView

func ShowView(view func(i *Interaction) Page) HandlerStep

ShowView is a final handler step that uses a callback to render the requested page.

func VerifyLogin

func VerifyLogin(e core.Engine) HandlerStep

VerifyLogin is a handler step that checks the current session for a valid login, and redirects to /login if it cannot find one.

func VerifyPermissions

func VerifyPermissions(perms core.Permissions) HandlerStep

VerifyPermissions is a handler step that checks whether the current user has at least the given permissions.

type Interaction

type Interaction struct {
	Req *http.Request

	//Slots for data associated with a request, which may be stored by one step
	//and then used by later steps.
	Session     *sessions.Session
	CurrentUser *core.UserWithPerms
	FormSpec    *h.FormSpec
	FormState   *h.FormState
	TargetUser  *core.User  //only used by CRUD views editing a single user
	TargetGroup *core.Group //only used by CRUD views editing a single group
	// contains filtered or unexported fields
}

Interaction describes a single invocation of Handler.ServeHTTP().

func (*Interaction) RedirectTo

func (i *Interaction) RedirectTo(url string)

RedirectTo redirects to the given URL.

func (*Interaction) RedirectWithFlashTo

func (i *Interaction) RedirectWithFlashTo(url string, f Flash)

RedirectWithFlashTo is like RedirectTo, but stores a flash to show on the next page.

func (*Interaction) SaveSession

func (i *Interaction) SaveSession() bool

SaveSession calls i.Session.Save(). When false is returned, a 500 error was written and the calling handler step shall abort immediately.

func (*Interaction) WriteError

func (i *Interaction) WriteError(msg string, code int)

WriteError wraps http.Error().

type Page

type Page struct {
	Status   int
	Title    string
	Contents template.HTML
	Wide     bool
}

Page describes a HTML page produced by Portunus.

func (Page) Render

func (p Page) Render(w http.ResponseWriter, r *http.Request, currentUser *core.UserWithPerms, s *sessions.Session)

Render renders the given page.

Jump to

Keyboard shortcuts

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