controller

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: Apache-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package controller defines common utilities used by web and API controllers.

Index

Constants

View Source
const (
	ContentTypeJSON = "application/json"
	ContentTypeHTML = "text/html"
)

Variables

View Source
var (
	MFirebaseRecreates = stats.Int64(metricPrefix+"/fb_recreates", "firebase user recreates", stats.UnitDimensionless)
)

Functions

func AuthorizedAppFromContext

func AuthorizedAppFromContext(ctx context.Context) *database.AuthorizedApp

AuthorizedAppFromContext retrieves the authorized app from the context. If no value exists, it returns nil.

func Back added in v0.3.0

Back goes back to the referrer.

func BindForm

func BindForm(w http.ResponseWriter, r *http.Request, data interface{}) error

BindForm parses and binds the HTTP form to the provided data interface using the gorilla schema package.

func BindJSON

func BindJSON(w http.ResponseWriter, r *http.Request, data interface{}) error

BindJSON provides a common implementation of JSON unmarshaling with well defined error handling.

func ClearEmailVerificationPrompted added in v0.9.0

func ClearEmailVerificationPrompted(session *sessions.Session)

ClearEmailVerificationPrompted clears the MFA prompt bit.

func ClearLastActivity added in v0.9.0

func ClearLastActivity(session *sessions.Session)

ClearLastActivity clears the session last activity time.

func ClearMFAPrompted added in v0.8.0

func ClearMFAPrompted(session *sessions.Session)

ClearMFAPrompted clears the MFA prompt bit.

func ClearPasswordExpireWarned added in v0.9.0

func ClearPasswordExpireWarned(session *sessions.Session)

ClearPasswordExpireWarned clears the welcome message prompt bit.

func ClearSessionRealm

func ClearSessionRealm(session *sessions.Session)

ClearSessionRealm clears the realm from the session.

func ClearWelcomeMessageDisplayed added in v0.9.0

func ClearWelcomeMessageDisplayed(session *sessions.Session)

ClearWelcomeMessageDisplayed clears the welcome message prompt bit.

func EmailVerificationPromptedFromSession added in v0.9.0

func EmailVerificationPromptedFromSession(session *sessions.Session) bool

EmailVerificationPromptedFromSession extracts if the user was prompted for email verification.

func FirebaseUserFromContext added in v0.10.0

func FirebaseUserFromContext(ctx context.Context) *auth.UserRecord

FirebaseUserFromContext retrieves the firebase user from the context. If no value exists, it returns nil.

func Flash

func Flash(session *sessions.Session) *flash.Flash

Flash gets or creates the flash data for the provided session.

func HandleHealthz added in v0.3.0

func HandleHealthz(ctx context.Context, cfg *database.Config, h *render.Renderer) http.Handler

func InternalError

func InternalError(w http.ResponseWriter, r *http.Request, h *render.Renderer, err error)

InternalError handles an internal error, returning the right response to the client.

func IsJSONContentType

func IsJSONContentType(r *http.Request) bool

IsJSONContentType returns true if the request's content type is application/json extra specific details, like UTF encoding schema are allowed.

func LastActivityFromSession added in v0.9.0

func LastActivityFromSession(session *sessions.Session) time.Time

LastActivityFromSession extracts the last time the user did something.

func MFAPromptedFromSession added in v0.8.0

func MFAPromptedFromSession(session *sessions.Session) bool

MFAPromptedFromSession extracts if the user was prompted for MFA.

func MissingAuthorizedApp

func MissingAuthorizedApp(w http.ResponseWriter, r *http.Request, h *render.Renderer)

MissingAuthorizedApp returns an internal error when the authorized app does not exist.

func MissingRealm

func MissingRealm(w http.ResponseWriter, r *http.Request, h *render.Renderer)

MissingRealm returns an error indicating that the request requires a realm selection, but one was not present.

func MissingSession

func MissingSession(w http.ResponseWriter, r *http.Request, h *render.Renderer)

MissingSession returns an internal error when the session does not exist.

func MissingUser

func MissingUser(w http.ResponseWriter, r *http.Request, h *render.Renderer)

MissingUser returns an internal error when the user does not exist.

func NotFound added in v0.12.1

func NotFound(w http.ResponseWriter, r *http.Request, h *render.Renderer)

NotFound returns an error indicating the URL was not found.

func PasswordExpireWarnedFromSession added in v0.9.0

func PasswordExpireWarnedFromSession(session *sessions.Session) bool

PasswordExpireWarnedFromSession extracts if the user was displayed the realm welcome message.

func RealmFromContext

func RealmFromContext(ctx context.Context) *database.Realm

RealmFromContext retrieves the realm from the context. If no value exists, it returns nil.

func RealmIDFromSession

func RealmIDFromSession(session *sessions.Session) uint

RealmIDFromSession extracts the realm from the session.

func RedirectToChangePassword added in v0.9.0

func RedirectToChangePassword(w http.ResponseWriter, r *http.Request, h *render.Renderer)

RedirectToChangePassword redirects to the password reset page.

func RedirectToMFA added in v0.8.0

func RedirectToMFA(w http.ResponseWriter, r *http.Request, h *render.Renderer)

RedirectToMFA redirects to the MFA registration.

func RequestIDFromContext added in v0.16.0

func RequestIDFromContext(ctx context.Context) string

RequestIDFromContext retrieves the request ID from the context. If no value exists, it returns the empty string.

func SendEmailVerificationEmailFunc added in v0.15.0

func SendEmailVerificationEmailFunc(ctx context.Context, db *database.Database, h *render.Renderer, email string) (auth.EmailVerificationEmailFunc, error)

SendEmailVerificationEmailFunc returns a function capable of sending an email verification email.

func SendInviteEmailFunc added in v0.15.0

func SendInviteEmailFunc(ctx context.Context, db *database.Database, h *render.Renderer, email string) (auth.InviteUserEmailFunc, error)

SendInviteEmailFunc returns a function capable of sending a new user invitation.

func SendPasswordResetEmailFunc added in v0.15.0

func SendPasswordResetEmailFunc(ctx context.Context, db *database.Database, h *render.Renderer, email string) (auth.ResetPasswordEmailFunc, error)

SendPasswordResetEmailFunc returns a function capable of sending a password reset for the given user.

func SessionFromContext

func SessionFromContext(ctx context.Context) *sessions.Session

SessionFromContext retrieves the session on the provided context. If no session exists, or if the value in the context is not of the correct type, it returns nil.

func StorePasswordExpireWarned added in v0.9.0

func StorePasswordExpireWarned(session *sessions.Session, prompted bool)

StorePasswordExpireWarned stores if the user was displayed the realm welcome message.

func StoreSessionEmailVerificationPrompted added in v0.9.0

func StoreSessionEmailVerificationPrompted(session *sessions.Session, prompted bool)

StoreSessionEmailVerificationPrompted stores if the user was prompted for email verification.

func StoreSessionLastActivity added in v0.9.0

func StoreSessionLastActivity(session *sessions.Session, t time.Time)

StoreSessionLastActivity stores the last time the user did something. This is used to track idle session timeouts.

func StoreSessionMFAPrompted added in v0.8.0

func StoreSessionMFAPrompted(session *sessions.Session, prompted bool)

StoreSessionMFAPrompted stores if the user was prompted for MFA.

func StoreSessionRealm

func StoreSessionRealm(session *sessions.Session, realm *database.Realm)

StoreSessionRealm stores the realm's ID in the session.

func StoreSessionWelcomeMessageDisplayed added in v0.9.0

func StoreSessionWelcomeMessageDisplayed(session *sessions.Session, prompted bool)

StoreSessionWelcomeMessageDisplayed stores if the user was displayed the realm welcome message.

func Unauthorized

func Unauthorized(w http.ResponseWriter, r *http.Request, h *render.Renderer)

Unauthorized returns an error indicating the request was unauthorized.

func UserFromContext

func UserFromContext(ctx context.Context) *database.User

UserFromContext retrieves the user from the context. If no value exists, it returns nil.

func WelcomeMessageDisplayedFromSession added in v0.9.0

func WelcomeMessageDisplayedFromSession(session *sessions.Session) bool

WelcomeMessageDisplayedFromSession extracts if the user was displayed the realm welcome message.

func WithAuthorizedApp

func WithAuthorizedApp(ctx context.Context, app *database.AuthorizedApp) context.Context

WithAuthorizedApp stores the authorized app on the context.

func WithFirebaseUser added in v0.10.0

func WithFirebaseUser(ctx context.Context, u *auth.UserRecord) context.Context

WithFirebaseUser stores the current firebase user on the context.

func WithRealm

func WithRealm(ctx context.Context, r *database.Realm) context.Context

WithRealm stores the current realm on the context.

func WithRequestID added in v0.16.0

func WithRequestID(ctx context.Context, id string) context.Context

WithRequestID stores the request ID on the context.

func WithSession

func WithSession(ctx context.Context, session *sessions.Session) context.Context

WithSession stores the session on the request's context for retrieval later. Use Session(r) to retrieve the session.

func WithTemplateMap

func WithTemplateMap(ctx context.Context, m TemplateMap) context.Context

WithTemplateMap creates a context with the given template map.

func WithUser

func WithUser(ctx context.Context, u *database.User) context.Context

WithUser stores the current user on the context.

Types

type TemplateMap

type TemplateMap map[string]interface{}

TemplateMap is a typemap for the HTML templates.

func TemplateMapFromContext

func TemplateMapFromContext(ctx context.Context) TemplateMap

TemplateMapFromContext gets the template map on the context. If no map exists, it returns an empty map.

func (TemplateMap) Title added in v0.16.0

func (m TemplateMap) Title(f string, args ...interface{})

Title sets the title on the template map. If a title already exists, the new value is prepended.

Directories

Path Synopsis
Package admin contains controllers for system wide administrative actions.
Package admin contains controllers for system wide administrative actions.
Package apikey contains web controllers for listing and adding API Keys.
Package apikey contains web controllers for listing and adding API Keys.
Package associated handles the iOS and Android associated app handler protocols.
Package associated handles the iOS and Android associated app handler protocols.
Package certapi implements the token + TEK verification API.
Package certapi implements the token + TEK verification API.
Package cleanup implements periodic data deletion.
Package cleanup implements periodic data deletion.
Package codestatus defines a web controller for the code status page of the verification server.
Package codestatus defines a web controller for the code status page of the verification server.
Package flash implements flash messages.
Package flash implements flash messages.
Package home defines a web controller for the home page of the verification server.
Package home defines a web controller for the home page of the verification server.
Package issueapi implements the API handler for taking a code request, assigning an OTP, saving it to the database and returning the result.
Package issueapi implements the API handler for taking a code request, assigning an OTP, saving it to the database and returning the result.
Package jwks handles returning JSON encoded information about the server's encryptionn keys.
Package jwks handles returning JSON encoded information about the server's encryptionn keys.
Package login defines the controller for the login page.
Package login defines the controller for the login page.
Package middleware contains application specific gin middleware functions.
Package middleware contains application specific gin middleware functions.
Package mobileapps contains web controllers for listing and adding mobile apps.
Package mobileapps contains web controllers for listing and adding mobile apps.
Package modeler implements periodic statistical calculations.
Package modeler implements periodic statistical calculations.
Package realmadmin contains web controllers for changing realm settings.
Package realmadmin contains web controllers for changing realm settings.
Package realmkeys contains web controllers for realm certificate key management.
Package realmkeys contains web controllers for realm certificate key management.
Package redirect defines the controller for the deep link redirector.
Package redirect defines the controller for the deep link redirector.
Package user contains web controllers for listing and adding users.
Package user contains web controllers for listing and adding users.
Package verifyapi implements the exchange of the verification code (short term token) for a long term token that can be used to get a verification certification to send to the key server.
Package verifyapi implements the exchange of the verification code (short term token) for a long term token that can be used to get a verification certification to send to the key server.

Jump to

Keyboard shortcuts

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