manage

package
v1.13.1-0...-fbee82e Latest Latest
Warning

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

Go to latest
Published: May 12, 2025 License: BSD-3-Clause Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// NoPerms allows anyone to access this Action
	NoPerms = iota
	// JanitorPerms allows anyone with at least a janitor-level account to access this Action
	JanitorPerms
	// ModPerms allows anyone with at least a moderator-level account to access this Action
	ModPerms
	// AdminPerms allows only the site administrator to view this Action
	AdminPerms
)
View Source
const (
	// NoJSON actions will return an error if JSON is requested by the user
	NoJSON = iota
	// OptionalJSON actions have an optional JSON output if requested
	OptionalJSON
	// AlwaysJSON actions always return JSON whether or not it is requested
	AlwaysJSON
)

Variables

View Source
var (
	ErrBadCredentials        = errors.New("invalid username or password")
	ErrUnableToCreateSession = errors.New("unable to create login session")
	ErrInvalidSession        = errors.New("invalid staff session")
)
View Source
var (
	ErrInsufficientPermission = server.NewServerError("insufficient account permission", http.StatusForbidden)
)
View Source
var (
	ErrPasswordsDoNotMatch = errors.New("passwords do not match")
)

Functions

func GetStaffFromRequest

func GetStaffFromRequest(request *http.Request) (*gcsql.Staff, error)

GetStaffFromRequest returns the staff making the request. If the request does not have a staff cookie, it will return a staff object with rank 0. Deprecated: use gcsql.GetStaffFromRequest

func GetStaffRank

func GetStaffRank(request *http.Request) int

GetStaffRank returns the rank number of the staff referenced in the request

func InitManagePages

func InitManagePages()

InitManagePages sets up the built-in manage pages

func PreloadModule

func PreloadModule(l *lua.LState) int

func RegisterManagePage

func RegisterManagePage(id string, title string, permissions int, jsonOutput int, callback CallbackFunction)

Types

type Action

type Action struct {
	// ID is the string used when the user requests /manage/<ID>
	ID string `json:"id"`

	// Title is used for the text shown in the staff menu and the window title
	Title string `json:"title"`

	// Permissions represent who can access the page. 0 for anyone,
	// 1 requires the user to have a janitor, mod, or admin account. 2 requires mod or admin,
	// and 3 is only accessible by admins
	Permissions int `json:"perms"`

	// Hidden is used to hide the action from the staff menu
	Hidden bool `json:"-"`

	// JSONoutput sets what the action can output. If it is 0, it will throw an error if
	// JSON is requested. If it is 1, it can output JSON if requested, and if 2, it always
	// outputs JSON whether it is requested or not
	JSONoutput int `json:"jsonOutput"` // if it can sometimes return JSON, this should still be false

	// Callback executes the staff page. if wantsJSON is true, it should return an object
	// to be marshalled into JSON. Otherwise, a string assumed to be valid HTML is returned.
	//
	// IMPORTANT: the writer parameter should only be written to if absolutely necessary (for example,
	// if a redirect wouldn't work in handler.go) and even then, it should be done sparingly
	Callback CallbackFunction `json:"-"`
}

Action represents the functions accessed by staff members at /manage/<functionname>.

type CallbackFunction

type CallbackFunction func(writer http.ResponseWriter, request *http.Request, staff *gcsql.Staff, wantsJSON bool, infoEv *zerolog.Event, errEv *zerolog.Event) (output any, err error)

type ErrStaffAction

type ErrStaffAction struct {
	// ErrorField can be used in the frontend for giving more specific info about the error
	ErrorField string `json:"error"`
	Action     string `json:"action"`
	Message    string `json:"message"`
}

func (*ErrStaffAction) Error

func (esa *ErrStaffAction) Error() string

Jump to

Keyboard shortcuts

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