forms

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultServerAddress = "http://localhost:1234"
	DefaultSetPWPath     = "/set-password"
	DefaultResetPWPath   = "/reset-password"
	DefaultLoginPath     = "/login"
	DefaultRedirectKey   = "redirect"
	DefaultTokenKey      = "jwt"
)

Defaults when Forms.Paths is nil, or field is empty.

View Source
const (
	// AllowedMethods for the handlers of this package
	AllowedMethods = http.MethodGet + " " + http.MethodPost
)
View Source
const DefaultLoginTmpl = `` /* 545-byte string literal not displayed */

DefaultLoginTmpl is a placeholder template for `Login`

View Source
const DefaultResetPWTmpl = `` /* 419-byte string literal not displayed */

DefaultResetPWTmpl is a placeholder template for `Login`

View Source
const DefaultSetPWTmpl = `` /* 431-byte string literal not displayed */

DefaultSetPWTmpl is a placeholder template for `Login`

Variables

View Source
var (
	LoginTitle   = "Please login"
	ResetPWTitle = "Reset password"
	SetPWTitle   = "Set new password"
)

Titles passed to templates

Functions

This section is empty.

Types

type Flash

type Flash struct {
	Lvl FlashLvl
	Msg string
}

Flash message targets the user with info, warning or error message

type FlashLvl

type FlashLvl string

FlashLvl indicates the severity of Flash

const (
	InfoFlashLvl FlashLvl = "info"
	WarnFlashLvl FlashLvl = "warning"
	ErrFlashLvl  FlashLvl = "error"
)

Predefined Flash levels

type FormData

type FormData struct {
	Title     string
	Flash     *Flash
	Nav       Navigation
	SubmitURL string
	Data      interface{} // As set on the Forms object
}

FormData is passed to the form templates

type Forms

type Forms struct {
	// Tmpl holds the login form template.
	// If nil a simple placholder is used.
	Tmpl *template.Template
	EP   ehtml.Pages
	// Data will be available in all templates.
	Data interface{}

	Client auth.AuthenticatorClient
	Paths  *Paths
}

Forms implements http.Forms. A GET request serves the login form. A POST request processes user login.

func (*Forms) LoginHander

func (f *Forms) LoginHander() http.Handler

LoginHander returns the handler taking care of login GET and POST requests. GET serves the "login" form template. POST checks the user's credentials over gRPC.

func (*Forms) ResetPWHandler

func (f *Forms) ResetPWHandler() http.Handler

ResetPWHandler returns the handler taking care of password setting, using a reset token. GET serves the "reset" form template. POST forwards the request over gPRC, which sends and an e-mail with a reset link to the submitted e-mail address, if it is registered.

func (*Forms) SetPWHandler

func (f *Forms) SetPWHandler() http.Handler

SetPWHandler returns the handler taking care of password setting, using a reset token. GET serves the "setpw" form template. POST checks the JWT and sets the new password over gRPC.

type Navigation struct {
	Login, Reset, Set template.URL
}

Navigation links to other forms

type Paths

type Paths struct {
	// Public address of the server.
	ServerAddress string `json:"server_address,omitempty"`
	SetPW         string `json:"set_pw,omitempty"`
	ResetPW       string `json:"reset_pw,omitempty"`
	Login         string `json:"login,omitempty"`
	// RedirectKey for redirect URL in request Query.
	// Upon successfull authentication, the client is redirected to the URL under this key.
	// Login request: https://example.com/login?redirect=https://secured.com/admin?key=value
	// Will redirect to: https://secured.com/admin?key=value&jwt=xxxxxxxxxxx
	RedirectKey string `json:"redirect_key,omitempty"`
	// TokenKey is under which key the JSON web token will be embedded in the URL query,
	// when executing the redirect.
	TokenKey string `json:"token_key,omitempty"`
}

Paths are used for generating Redirect responses, e-mailed links and route generation. All paths must be absolute, with leading slash.

type TemplateName

type TemplateName string

TemplateName is used to predefine template naming requirements.

const (
	LoginTmpl   TemplateName = "login"
	ResetPWTmpl TemplateName = "reset"
	SetPWTmpl   TemplateName = "setpw"
)

Predefined Template Names.

Jump to

Keyboard shortcuts

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