httputils

package
v0.0.0-...-16966e3 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	SessionKeyUserID    = "user_id"
	SessionKeyGroups    = "groups"
	SessionKeyAuthState = "auth_state"
	SessionKeyMessages  = "messages"
)
View Source
var (
	ErrNotAuthorized = errors.New("you are not allowed to do that")
)

Functions

func AddUserToGroupInSession

func AddUserToGroupInSession(c echo.Context, group string) error

Updates the session store to indicate the current user is in a group that the IDP did not tell us they were in when the user logged in. Should only be used when the IDP is also being told that the user is being added to the group, to allow the user to instantly use their newfound powers.

func AuthMiddleware

func AuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func CSRFMiddleware

func CSRFMiddleware() echo.MiddlewareFunc

func DatabaseFromContext

func DatabaseFromContext(c echo.Context) *db.Queries

DatabaseFromContext retrieves the database queries from the context. This must only be called from a request that has passed through the WithDatabase middleware.

func DeleteSession

func DeleteSession(c echo.Context) error

func GetCSRFToken

func GetCSRFToken(c echo.Context) string

func GetMessagesOnSession

func GetMessagesOnSession(c echo.Context) ([]string, error)

func GetUser

func GetUser(c echo.Context) *db.User

func HTTPError

func HTTPError(code int, err error) error

HTTPError creates a new HTTP error with the specified status code and error value. It is a simple wrapper for echo.NewHTTPError.

func HTTPErrorf

func HTTPErrorf(code int, format string, args ...any) error

HTTPErrorf creates a new HTTP error with the specified status code and formatted error message.

func HasAnyGroups

func HasAnyGroups(c echo.Context, groups ...string) bool

HasAnyGroups returns true if the logged in user has at least one of the listed groups

func InitializeAuthRoutes

func InitializeAuthRoutes(g *echo.Group)

func OptionalAuthMiddleware

func OptionalAuthMiddleware(next echo.HandlerFunc) echo.HandlerFunc

OptionalAuthMiddleware checks if the user is logged in, but doesn't prevent access if they aren't (user from context may be nil when using this)

func RemoveUserFromGroupInSession

func RemoveUserFromGroupInSession(c echo.Context, group string) error

Updates the session store to indicate the current user is not in a group that the IDP told us they were in when the user logged in. Should only be used when the IDP is also being told that theu ser is being removed from the group.

func RenderMessages

func RenderMessages(messages []string) template.HTML

func RequireGroupMiddleware

func RequireGroupMiddleware(group string) echo.MiddlewareFunc

func Session

func Session(c echo.Context) (*sessions.Session, error)

func SetMessageOnSession

func SetMessageOnSession(c echo.Context, messages ...string) error

func WithDatabase

func WithDatabase(next echo.HandlerFunc) echo.HandlerFunc

WithDatabase is an Echo middleware that retrieves a database connection and sets it in the context for the request.

Types

This section is empty.

Jump to

Keyboard shortcuts

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