web

package
v0.0.0-...-5733806 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: AGPL-3.0 Imports: 40 Imported by: 0

Documentation

Overview

Package web is the client-side router that manages the website If the `server` package interacts with the DB, the `web` package interacts with the user

Index

Constants

View Source
const (
	PblistCntCacheKey = WebCtx("pblist_cache")
)

Variables

View Source
var (
	DonationsEnabled = config.GenFlag[bool]("frontend.donations.enabled", true, "Donations page enabled")
	DonationsNag     = config.GenFlag[bool]("frontent.donation.frontpage_nag", true, "Donations front page notification")

	MainPageLogin = config.GenFlag[bool]("feature.frontend.main_page_login", false, "Login modal on front page")
)
View Source
var (
	CCDisclaimer = config.GenFlag("feature.frontend.cc_disclaimer", true, "CC disclaimer in footer")

	AllSubsPage = config.GenFlag("feature.frontend.all_subs_page", true, "Anyone can view all submissions")

	FrontPageProblems = config.GenFlag("feature.frontend.front_page_pbs", true, "Show problems on front page")

	ForceLogin = config.GenFlag("behavior.force_authed", false, "Force authentication when accessing website")
)

Functions

func ReadOrTruncate

func ReadOrTruncate(r io.Reader) ([]byte, bool)

Types

type AttachmentEditorParams

type AttachmentEditorParams struct {
	Attachments []*kilonova.Attachment
	Problem     *kilonova.Problem
	BlogPost    *kilonova.BlogPost

	APIPrefix string
}

type AuditLogParams

type AuditLogParams struct {
	Ctx *ReqContext

	Logs     []*kilonova.AuditLog
	Page     int
	NumPages int
}

type BlogPostIndexParams

type BlogPostIndexParams struct {
	Ctx *ReqContext

	Posts   []*kilonova.BlogPost
	Authors map[int]*kilonova.UserBrief

	Page     int
	NumPages int
}

type BlogPostParams

type BlogPostParams struct {
	Ctx *ReqContext

	Topbar *PostTopbar

	StatementEditor  *StatementEditorParams
	AttachmentEditor *AttachmentEditorParams

	Attachments []*kilonova.Attachment

	Statement    template.HTML
	StatementAtt *kilonova.Attachment
	Languages    map[string]eval.Language
	Variants     []*kilonova.StatementVariant

	SelectedLang   string
	SelectedFormat string
}

type ContestParams

type ContestParams struct {
	Ctx    *ReqContext
	Topbar *ProblemTopbar

	Contest *kilonova.Contest
}

type ContestsIndexParams

type ContestsIndexParams struct {
	Ctx *ReqContext

	Contests []*kilonova.Contest
}

type DonateParams

type DonateParams struct {
	Ctx *ReqContext

	Donations []*kilonova.Donation

	Status   string
	BMACName string
	PayPalID string
}

type IndexParams

type IndexParams struct {
	Ctx *ReqContext

	FutureContests  []*kilonova.Contest
	RunningContests []*kilonova.Contest

	ChildProblemLists []*kilonova.ProblemList

	HotProblems  []*kilonova.ScoredProblem
	MoreProblems bool

	PinnedLists []*kilonova.ProblemList
}

type MarkdownParams

type MarkdownParams struct {
	Ctx      *ReqContext
	Markdown template.HTML
	Title    string
}

type PasswordResetParams

type PasswordResetParams struct {
	Ctx *ReqContext

	User      *kilonova.UserFull
	RequestID string
}

type PasteParams

type PasteParams struct {
	Ctx   *ReqContext
	Paste *kilonova.SubmissionPaste

	FullSub *sudoapi.FullSubmission
}

type PblistParams

type PblistParams struct {
	Pblist *kilonova.ProblemList
	Open   bool
}

type PostTopbar

type PostTopbar struct {
	IsPostEditor bool

	Post *kilonova.BlogPost

	Page string
}

type ProblemEditParams

type ProblemEditParams struct {
	Ctx     *ReqContext
	Problem *kilonova.Problem
	Topbar  *ProblemTopbar

	Checklist *kilonova.ProblemChecklist

	AttachmentEditor *AttachmentEditorParams
	StatementEditor  *StatementEditorParams
}

type ProblemListParams

type ProblemListParams struct {
	Ctx         *ReqContext
	ProblemList *kilonova.ProblemList
	Lists       []*kilonova.ProblemList

	RootProblemList int
}

type ProblemListProgressParams

type ProblemListProgressParams struct {
	Ctx         *ReqContext
	ProblemList *sudoapi.FullProblemList
	CheckedUser *kilonova.UserBrief
}

type ProblemListingParams

type ProblemListingParams struct {
	Problems  []*kilonova.ScoredProblem
	ShowScore bool

	ShowPublished bool

	ContestIDScore int
}

type ProblemParams

type ProblemParams struct {
	Ctx    *ReqContext
	Topbar *ProblemTopbar

	Problem     *kilonova.Problem
	Attachments []*kilonova.Attachment
	Tags        []*kilonova.Tag

	Submissions *sudoapi.Submissions

	Statement template.HTML
	Languages map[string]eval.Language
	Variants  []*kilonova.StatementVariant

	SelectedLang   string
	SelectedFormat string
}

type ProblemSearchParams

type ProblemSearchParams struct {
	Ctx *ReqContext

	Results   []*sudoapi.FullProblem
	Groups    []*kilonova.TagGroup
	GroupTags []*kilonova.Tag
	Count     int
}

type ProblemTopbar

type ProblemTopbar struct {
	IsProblemEditor bool
	IsContestEditor bool
	CanViewTests    bool

	Contest *kilonova.Contest
	Problem *kilonova.Problem

	URLPrefix string

	Page   string
	PageID int
}

type ProblemTopbarParams

type ProblemTopbarParams struct {
	Ctx    *ReqContext
	Topbar *ProblemTopbar

	Languages map[string]eval.Language
	Problem   *kilonova.Problem
}

type ProfileParams

type ProfileParams struct {
	Ctx *ReqContext

	ContentUser       *kilonova.UserFull
	SolvedProblems    []*sudoapi.FullProblem
	SolvedCount       int
	AttemptedProblems []*sudoapi.FullProblem
	AttemptedCount    int

	ChangeHistory []*kilonova.UsernameChange
}

type ReqContext

type ReqContext struct {
	User     *kilonova.UserFull
	Language string
}

func GenContext

func GenContext(r *http.Request) *ReqContext

type SimpleParams

type SimpleParams struct {
	Ctx *ReqContext
}

type StatementEditorParams

type StatementEditorParams struct {
	Lang string
	Data string
	Att  *kilonova.Attachment

	APIPrefix string
}

type StatusParams

type StatusParams struct {
	Ctx *ReqContext

	Code    int
	Message string
}

type SubParams

type SubParams struct {
	Ctx        *ReqContext
	Submission *kilonova.FullSubmission
}

type SubTaskEditParams

type SubTaskEditParams struct {
	Ctx     *ReqContext
	Problem *kilonova.Problem
	SubTask *kilonova.SubTask
	Topbar  *ProblemTopbar
	// contains filtered or unexported fields
}

func (*SubTaskEditParams) TestInSubTask

func (s *SubTaskEditParams) TestInSubTask(test *kilonova.Test) bool

func (*SubTaskEditParams) TestSubTasks

func (s *SubTaskEditParams) TestSubTasks(id int) string

type TagPageParams

type TagPageParams struct {
	Ctx *ReqContext

	Tag *kilonova.Tag

	RelevantTags []*kilonova.Tag
	Problems     []*kilonova.ScoredProblem
}

type TestEditParams

type TestEditParams struct {
	Ctx     *ReqContext
	Problem *kilonova.Problem
	Test    *kilonova.Test
	Topbar  *ProblemTopbar
	// contains filtered or unexported fields
}

func (*TestEditParams) GetFullTests

func (t *TestEditParams) GetFullTests() testDataType

type VerifiedEmailParams

type VerifiedEmailParams struct {
	Ctx *ReqContext

	ContentUser *kilonova.UserBrief
}

type Web

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

Web is the struct representing this whole package

func NewWeb

func NewWeb(debug bool, base *sudoapi.BaseAPI) *Web

NewWeb returns a new web instance

func (*Web) Handler

func (rt *Web) Handler() http.Handler

Handler returns a http.Handler

func (*Web) ProblemEditRouter

func (rt *Web) ProblemEditRouter(r chi.Router)

Handler is the http handler to be attached The caller should ensure a User and a Problem are attached to the context

func (*Web) SubTaskValidator

func (rt *Web) SubTaskValidator() func(next http.Handler) http.Handler

func (*Web) TestIDValidator

func (rt *Web) TestIDValidator() func(next http.Handler) http.Handler

func (*Web) ValidateAttachmentID

func (rt *Web) ValidateAttachmentID(next http.Handler) http.Handler

ValidateAttachmentID makes sure the attachment ID is a valid uint

func (*Web) ValidateBlogPostSlug

func (rt *Web) ValidateBlogPostSlug(next http.Handler) http.Handler

ValidateBlogPostSlug makes sure the blog post slug is a valid one

func (*Web) ValidateBlogPostVisible

func (rt *Web) ValidateBlogPostVisible(next http.Handler) http.Handler

ValidateBlogPostVisible checks if the post from context is visible from the logged in user

func (*Web) ValidateContestID

func (rt *Web) ValidateContestID(next http.Handler) http.Handler

ValidateContestID makes sure the contest ID is a valid uint

func (*Web) ValidateContestVisible

func (rt *Web) ValidateContestVisible(next http.Handler) http.Handler

ValidateContestVisible checks if the problem from context is visible from the logged in user

func (*Web) ValidateListID

func (rt *Web) ValidateListID(next http.Handler) http.Handler

ValidateListID makes sure the list ID is a valid uint

func (*Web) ValidatePasteID

func (rt *Web) ValidatePasteID(next http.Handler) http.Handler

ValidatePasteID puts the ID and the Paste in the router context

func (*Web) ValidateProblemFullyVisible

func (rt *Web) ValidateProblemFullyVisible(next http.Handler) http.Handler

ValidateProblemFullyVisible checks if the problem from context is FULLY visible from the logged in user

func (*Web) ValidateProblemID

func (rt *Web) ValidateProblemID(next http.Handler) http.Handler

ValidateProblemID makes sure the problem ID is a valid uint

func (*Web) ValidateProblemVisible

func (rt *Web) ValidateProblemVisible(next http.Handler) http.Handler

ValidateProblemVisible checks if the problem from context is visible from the logged in user

func (*Web) ValidateSubmissionID

func (rt *Web) ValidateSubmissionID(next http.Handler) http.Handler

ValidateSubmissionID puts the ID and the Submission in the router context

func (*Web) ValidateTagID

func (rt *Web) ValidateTagID(next http.Handler) http.Handler

ValidateTagID makes sure the tag ID is a valid uint

type WebCtx

type WebCtx string

type WebLanguage

type WebLanguage struct {
	Disabled bool   `json:"disabled"`
	Name     string `json:"name"`
}

Jump to

Keyboard shortcuts

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