Documentation
¶
Index ¶
- Constants
- Variables
- func GenerateResourceUUID() string
- func GenerateSalt() string
- func GetConfig(db *gorm.DB, key string) string
- func GetContestCount(db *gorm.DB) uint
- func GetPasswordHash(password string, salt string) string
- func GetProblemID(db *gorm.DB, contestID uint, alias string) (uint, error)
- func GetSubmissionCount(db *gorm.DB) uint
- func GetUserCount(db *gorm.DB) uint
- func HasEmail(db *gorm.DB, email string) bool
- func HasPendingApplication(db *gorm.DB, teamID, userID uint) bool
- func HasPendingInvitation(db *gorm.DB, teamID, userID uint) bool
- func HasProblemAlias(db *gorm.DB, contestID uint, alias string) bool
- func HasTeamName(db *gorm.DB, name string) bool
- func HasUsername(db *gorm.DB, username string) bool
- func IsContestAdmin(db *gorm.DB, contestID, userID uint) bool
- func IsTeamMemberByUserID(db *gorm.DB, teamID uint, userID uint) bool
- func MigrateSystem(db *gorm.DB)
- func SetConfig(db *gorm.DB, key string, value string)
- func SetItem()
- type Config
- type Contest
- func GetContestByID(db *gorm.DB, id uint) (*Contest, error)
- func GetContests(db *gorm.DB) []Contest
- func GetContestsFilterByStatus(db *gorm.DB, status uint) []Contest
- func GetDefaultContest(db *gorm.DB) *Contest
- func NewContest(db *gorm.DB, name string, description string, startTime time.Time, ...) *Contest
- func (c *Contest) AddAdmin(db *gorm.DB, user *User)
- func (c *Contest) AddNotification(db *gorm.DB, content string) int
- func (c *Contest) AddProblem(db *gorm.DB, problem *Problem)
- func (c *Contest) AddResource(db *gorm.DB, res *Resource)
- func (c *Contest) AddTeam(db *gorm.DB, team *Team, usersID []uint) error
- func (c *Contest) Delete(db *gorm.DB)
- func (c *Contest) DeleteAdmin(db *gorm.DB, user *User)
- func (c *Contest) DeleteTeamByID(db *gorm.DB, teamID uint) error
- func (c *Contest) GenerateRank(db *gorm.DB)
- func (c *Contest) GetAdmins(db *gorm.DB) []User
- func (c *Contest) GetNotificationByOrder(db *gorm.DB, order int) (*ContestNotification, error)
- func (c *Contest) GetNotifications(db *gorm.DB, from time.Time, offset uint) []ContestNotification
- func (c *Contest) GetProblems(db *gorm.DB) []Problem
- func (c *Contest) GetTeamSnapshots(db *gorm.DB) []TeamSnapshot
- func (c *Contest) GetTeams(db *gorm.DB) []Team
- func (c *Contest) GetUserTeam(db *gorm.DB, user *User) (*Team, error)
- func (c *Contest) HasPlayerByUserID(db *gorm.DB, usersID []uint) bool
- func (c *Contest) HasTeamByTeamID(db *gorm.DB, teamID uint) bool
- func (c *Contest) IsAdmin(db *gorm.DB, user *User) bool
- func (c *Contest) IsPlayer(db *gorm.DB, user *User) bool
- func (c *Contest) Update(db *gorm.DB)
- type ContestNotification
- type ContestRank
- type Flag
- type FlagSettings
- type FlagStatic
- type FlagType
- type Hint
- type Notification
- func GetNotificationByID(db *gorm.DB, id uint) (*Notification, error)
- func GetNotifications(db *gorm.DB, offset uint, limit uint) []Notification
- func GetUserNotifications(db *gorm.DB, user *User, offset uint) []Notification
- func NewNotification(db *gorm.DB, userID uint, content string, creatorID uint) *Notification
- type Problem
- func (p *Problem) AddFlag(db *gorm.DB, ft FlagType, fs FlagSettings) int
- func (p *Problem) AddFlagWithSettingsMap(db *gorm.DB, ft FlagType, m map[string]interface{}) (int, error)
- func (p *Problem) AddHint(db *gorm.DB, cost uint, content string) int
- func (p *Problem) AddResource(db *gorm.DB, res *Resource)
- func (p *Problem) AddSolver(db *gorm.DB, u *User)
- func (p *Problem) AddTag(db *gorm.DB, tag string)
- func (p *Problem) Delete(db *gorm.DB)
- func (p *Problem) DeleteTag(db *gorm.DB, tagName string)
- func (p *Problem) GetFlagByOrder(db *gorm.DB, order int) (*Flag, error)
- func (p *Problem) GetFlags(db *gorm.DB) []Flag
- func (p *Problem) GetHintByOrder(db *gorm.DB, order int) (*Hint, error)
- func (p *Problem) GetHints(db *gorm.DB) []Hint
- func (p *Problem) GetResources(db *gorm.DB) []Resource
- func (p *Problem) GetSolvers(db *gorm.DB) []User
- func (p *Problem) GetTags(db *gorm.DB) []ProblemTag
- func (p *Problem) GetTagsName(db *gorm.DB) []string
- func (p *Problem) Update(db *gorm.DB)
- type ProblemTag
- type Resource
- func GetContestResources(db *gorm.DB, contestID uint) []Resource
- func GetProblemResources(db *gorm.DB, problemID uint) []Resource
- func GetResourceByUUID(db *gorm.DB, resourceUUID string) (*Resource, error)
- func GetResources(db *gorm.DB) []Resource
- func NewResourceWithReader(db *gorm.DB, baseDir string, name string, contentType string, src io.Reader, ...) *Resource
- type Session
- func (s *Session) Del(rp *redis.Pool, key string)
- func (s *Session) Destroy(db *gorm.DB, rp *redis.Pool)
- func (s *Session) Get(rp *redis.Pool, key string, value interface{})
- func (s *Session) IsExpired() bool
- func (s *Session) IsLoggedIn() bool
- func (s *Session) Renew(db *gorm.DB, d time.Duration)
- func (s *Session) Set(rp *redis.Pool, key string, value interface{})
- func (s *Session) Update(db *gorm.DB)
- type Submission
- type System
- type Team
- func (t *Team) AddAdmin(db *gorm.DB, user *User)
- func (t *Team) AddMember(db *gorm.DB, user *User)
- func (t *Team) CalcContestPoints(db *gorm.DB, contest *Contest) (points uint)
- func (t *Team) Delete(db *gorm.DB)
- func (t *Team) DeleteAdmin(db *gorm.DB, user *User)
- func (t *Team) DeleteMember(db *gorm.DB, user *User)
- func (t *Team) GenerateInvitationToken(db *gorm.DB)
- func (t *Team) GetAdmins(db *gorm.DB) []User
- func (t *Team) GetContestRank(db *gorm.DB, contest *Contest) (*ContestRank, error)
- func (t *Team) GetContests(db *gorm.DB) []Contest
- func (t *Team) GetCorrectSubmissions(db *gorm.DB, contest *Contest) []Submission
- func (t *Team) GetMembers(db *gorm.DB, query string) []User
- func (t *Team) GetMembersCount(db *gorm.DB) uint
- func (t *Team) GetSnapshotByContestID(db *gorm.DB, contestID uint) (*TeamSnapshot, error)
- func (t *Team) GetSnapshots(db *gorm.DB) []TeamSnapshot
- func (t *Team) GetSolvedProblems(db *gorm.DB, contest *Contest) []Problem
- func (t *Team) GetUnlockedHints(db *gorm.DB, contest *Contest) []Hint
- func (t *Team) IsAdmin(db *gorm.DB, user *User) bool
- func (t *Team) IsAdminByUserID(db *gorm.DB, userID uint) bool
- func (t *Team) IsAllMemberByUserID(db *gorm.DB, userID []uint) bool
- func (t *Team) IsMember(db *gorm.DB, user *User) bool
- func (t *Team) IsMemberByUserID(db *gorm.DB, userID uint) bool
- func (t *Team) NewSnapshot(db *gorm.DB, contest *Contest, usersID []uint) (*TeamSnapshot, error)
- func (t *Team) Update(db *gorm.DB)
- type TeamApplication
- func GetPendingApplication(db *gorm.DB, teamID, userID uint) (*TeamApplication, error)
- func GetTeamApplications(db *gorm.DB, teamID uint) []TeamApplication
- func GetUserApplications(db *gorm.DB, userID uint) []TeamApplication
- func NewTeamApplication(db *gorm.DB, team *Team, userID uint) *TeamApplication
- type TeamInvitation
- func GetPendingInvitation(db *gorm.DB, teamID, userID uint) (*TeamInvitation, error)
- func GetTeamInvitations(db *gorm.DB, teamID uint) []TeamInvitation
- func GetUserInvitations(db *gorm.DB, userID uint) []TeamInvitation
- func NewTeamInvitation(db *gorm.DB, team *Team, toUserID, fromUserID uint) *TeamInvitation
- type TeamSnapshot
- type User
- func GetAdmins(db *gorm.DB) []User
- func GetUserByID(db *gorm.DB, id uint) (*User, error)
- func GetUserByUsername(db *gorm.DB, username string) (*User, error)
- func GetUsers(db *gorm.DB) []User
- func GetUsersByID(db *gorm.DB, id []uint) []User
- func GetUsersWithQuery(db *gorm.DB, offset, limit uint, query string) []User
- func NewUser(db *gorm.DB, username string, password string) (*User, error)
- func (u *User) CalcPersonalContestPoints(db *gorm.DB, contest *Contest) (points uint)
- func (u *User) CalcTeamContestPoints(db *gorm.DB, contest *Contest) (uint, error)
- func (u *User) ChangePassword(db *gorm.DB, password string)
- func (u *User) Delete(db *gorm.DB)
- func (u *User) GetContestTeam(db *gorm.DB, contest *Contest) (*Team, error)
- func (u *User) GetSolvedProblems(db *gorm.DB, contest *Contest) []Problem
- func (u *User) HasContestAccess(db *gorm.DB, contest *Contest) bool
- func (u *User) HasResourceAccess(db *gorm.DB, res *Resource) bool
- func (u *User) HasTeamAccess(db *gorm.DB, team *Team) bool
- func (u *User) IsContestAdmin(db *gorm.DB, contest *Contest) bool
- func (u *User) IsResourceAdmin(res *Resource) bool
- func (u *User) IsTeamAdmin(db *gorm.DB, team *Team) bool
- func (u *User) MatchPassword(password string) bool
- func (u *User) Update(db *gorm.DB)
- type UserProfile
Constants ¶
View Source
const ( ContestAccessRegister = iota ContestAccessPrivate TableContest = "contest" TableContestNotification = "contest_notification" TableRelContestAdmin = "rel_contest_admin" TableContestRank = "contest_rank" )
View Source
const ( FlagTypeStatic = "static" TableFlag = "flag" )
View Source
const ( TableProblem = "problem" TableProblemTag = "problem_tag" TableRelProblemTag = "rel_problem_tag" TableRelProblemSolver = "rel_problem_solver" )
View Source
const ( Correct = iota + 1 Wrong TableSubmission = "submission" )
View Source
const ( TableTeam = "team" TableRelTeamAdmin = "rel_team_admin" TableTeamSnapshot = "team_snapshot" TableRelTeamSnapshotMember = "rel_team_snapshot_member" TableTeamInvitation = "team_invitation" TableTeamApplication = "team_application" )
View Source
const ( InvitationPending = iota + 1 InvitationAccepted InvitationRejected InvitationFailed )
View Source
const ( ApplicationPending = iota + 1 ApplicationAccepted ApplicationRejected ApplicationFailed )
View Source
const ( DefaultUserTeamPrefix = "~FlagField__defaultTeam" DefaultUserTeamDescription = "This is the default team for a single user." TableUser = "user" TableUserProfile = "user_profile" TableRelUserTeam = "rel_user_team" TableRelUserUnlockedHint = "rel_user_unlocked_hint" )
View Source
const (
TableConfig = "config"
)
View Source
const (
TableHint = "hint"
)
View Source
const (
TableNotification = "notification"
)
View Source
const (
TableResource = "resource"
)
View Source
const (
TableSession = "session"
)
Variables ¶
View Source
var ( DefaultContest = Contest{ Name: "~FlagField__defaultContest", Description: "This is the default contest for Practice. Please do not delete this.", StartTime: time.Date(2000, 1, 1, 0, 0, 0, 0, time.UTC), EndTime: constants.MaxTime, Access: 0, IsHidden: true, CreatorID: 0, } )
View Source
var (
DefaultUser = User{
Username: "~FlagField__guest",
PasswordHash: "",
}
)
Functions ¶
func GenerateResourceUUID ¶
func GenerateResourceUUID() string
func GenerateSalt ¶
func GenerateSalt() string
func GetContestCount ¶
func GetPasswordHash ¶
func GetSubmissionCount ¶
func GetUserCount ¶
func MigrateSystem ¶
Types ¶
type Config ¶
func GetConfigs ¶
type Contest ¶
type Contest struct { gorm.Model Name string `gorm:"size:50;not null"` Description string `gorm:"type:longtext"` StartTime time.Time EndTime time.Time Access uint IsHidden bool CreatorID uint Problems []*Problem Admins []*User `gorm:"many2many:rel_contest_admin"` TeamSnapshots []*TeamSnapshot `gorm:"foreignkey:ContestID"` Resources []*Resource Notifications []*ContestNotification }
func GetContests ¶
func GetDefaultContest ¶
func NewContest ¶
func (*Contest) AddNotification ¶
func (*Contest) AddProblem ¶
Add association
func (*Contest) DeleteTeamByID ¶
TeamDelete association
func (*Contest) GetNotificationByOrder ¶
Get association
func (*Contest) GetNotifications ¶
func (*Contest) GetTeamSnapshots ¶
func (c *Contest) GetTeamSnapshots(db *gorm.DB) []TeamSnapshot
func (*Contest) HasPlayerByUserID ¶
type ContestNotification ¶
func (*ContestNotification) Delete ¶
func (n *ContestNotification) Delete(db *gorm.DB)
type ContestRank ¶
type Flag ¶
type Flag struct { gorm.Model ProblemID uint Type string `gorm:"not null"` SettingsPlain []byte `gorm:"column:settings,type:longtext"` Settings FlagSettings `gorm:"-"` }
func (*Flag) BeforeSave ¶
type FlagSettings ¶
type FlagSettings interface { Type() string FromMap(*map[string][]string) error FromPlain([]byte) error Plain() []byte Check(string) bool IsValid() bool }
func NewFlagSettingsFromMap ¶
func NewFlagSettingsFromMap(ft FlagType, m map[string]interface{}) (fs FlagSettings, err error)
type FlagStatic ¶
type FlagStatic struct {
Flag string `json:"flag"`
}
func (*FlagStatic) Check ¶
func (f *FlagStatic) Check(s string) bool
func (*FlagStatic) FromPlain ¶
func (f *FlagStatic) FromPlain(b []byte) error
func (*FlagStatic) IsValid ¶
func (f *FlagStatic) IsValid() bool
func (*FlagStatic) Plain ¶
func (f *FlagStatic) Plain() (j []byte)
func (*FlagStatic) Type ¶
func (f *FlagStatic) Type() string
type Hint ¶
type Hint struct { gorm.Model ProblemID uint Cost uint Content string `gorm:"type:longtext"` UnlockedUsers []*User `gorm:"many2many:rel_user_unlocked_hint"` }
func (*Hint) IsUnlocked ¶
type Notification ¶
type Notification struct { gorm.Model UserID uint Content string `gorm:"type:longtext"` IsRead bool CreatorID uint }
func GetNotificationByID ¶
func GetNotificationByID(db *gorm.DB, id uint) (*Notification, error)
func GetNotifications ¶
func GetNotifications(db *gorm.DB, offset uint, limit uint) []Notification
func GetUserNotifications ¶
func GetUserNotifications(db *gorm.DB, user *User, offset uint) []Notification
func NewNotification ¶
func (*Notification) Delete ¶
func (n *Notification) Delete(db *gorm.DB)
func (*Notification) Update ¶
func (n *Notification) Update(db *gorm.DB)
type Problem ¶
type Problem struct { gorm.Model Name string `gorm:"size:50;not null"` Description string `gorm:"type:longtext"` Alias string `gorm:"size:50;not null"` ContestID uint Points uint Type string `gorm:"size:50;not null"` IsHidden bool CreatorID uint Flags []*Flag Hints []*Hint Resources []*Resource Submissions []*Submission Solvers []*User `gorm:"many2many:rel_problem_solver"` Tags []*ProblemTag `gorm:"many2many:rel_problem_tag"` }
func NewProblem ¶
func (*Problem) AddFlagWithSettingsMap ¶
func (*Problem) GetFlagByOrder ¶
func (*Problem) GetHintByOrder ¶
type ProblemTag ¶
type Resource ¶
type Resource struct { gorm.Model UUID string `gorm:"unique;not null"` Name string `gorm:"size:255;not null"` Path string `gorm:"size:4096;not null"` ContentType string `gorm:"not null"` ExpiredAt time.Time IsHidden bool CreatorID uint ContestID uint ProblemID uint }
func GetResourceByUUID ¶
func GetResources ¶
func NewResourceWithReader ¶
type Session ¶
type Session struct { gorm.Model SessionID string `gorm:"size:32;unique;not null"` User *User UserID uint ExpireAt time.Time }
func GetSessionBySessionID ¶
func GetSessions ¶
func (*Session) IsLoggedIn ¶
type Submission ¶
type Submission struct { gorm.Model Flag string `gorm:"type:longtext"` Result uint ProblemID uint CreatorID uint }
func GetSubmissions ¶
func GetSubmissions(db *gorm.DB) []Submission
func NewSubmission ¶
type Team ¶
type Team struct { gorm.Model Name string `gorm:"size:50;unique;not null"` Description string `gorm:"type:longtext"` Members []*User `gorm:"many2many:rel_user_team"` Admins []*User `gorm:"many2many:rel_team_admin"` Snapshots []*TeamSnapshot `gorm:"foreignkey:TeamID"` CreatorID uint IsDefault bool InvitationToken string `gorm:"size:32"` }
func (*Team) CalcContestPoints ¶
Calculate points in contest
func (*Team) DeleteMember ¶
TeamDelete associations
func (*Team) GenerateInvitationToken ¶
Invitation token
func (*Team) GetContestRank ¶
func (*Team) GetCorrectSubmissions ¶
func (t *Team) GetCorrectSubmissions(db *gorm.DB, contest *Contest) []Submission
func (*Team) GetMembers ¶
Get associations
func (*Team) GetSnapshotByContestID ¶
func (*Team) GetSnapshots ¶
func (t *Team) GetSnapshots(db *gorm.DB) []TeamSnapshot
func (*Team) GetSolvedProblems ¶
func (*Team) GetUnlockedHints ¶
func (*Team) IsAllMemberByUserID ¶
Permission check
func (*Team) NewSnapshot ¶
type TeamApplication ¶
func GetPendingApplication ¶
func GetPendingApplication(db *gorm.DB, teamID, userID uint) (*TeamApplication, error)
func GetTeamApplications ¶
func GetTeamApplications(db *gorm.DB, teamID uint) []TeamApplication
func GetUserApplications ¶
func GetUserApplications(db *gorm.DB, userID uint) []TeamApplication
func NewTeamApplication ¶
func NewTeamApplication(db *gorm.DB, team *Team, userID uint) *TeamApplication
func (*TeamApplication) Delete ¶
func (app *TeamApplication) Delete(db *gorm.DB)
func (*TeamApplication) Update ¶
func (app *TeamApplication) Update(db *gorm.DB)
type TeamInvitation ¶
func GetPendingInvitation ¶
func GetPendingInvitation(db *gorm.DB, teamID, userID uint) (*TeamInvitation, error)
func GetTeamInvitations ¶
func GetTeamInvitations(db *gorm.DB, teamID uint) []TeamInvitation
func GetUserInvitations ¶
func GetUserInvitations(db *gorm.DB, userID uint) []TeamInvitation
func NewTeamInvitation ¶
func NewTeamInvitation(db *gorm.DB, team *Team, toUserID, fromUserID uint) *TeamInvitation
func (*TeamInvitation) Delete ¶
func (inv *TeamInvitation) Delete(db *gorm.DB)
func (*TeamInvitation) Update ¶
func (inv *TeamInvitation) Update(db *gorm.DB)
type TeamSnapshot ¶
type TeamSnapshot struct { gorm.Model TeamID uint ContestID uint Members []*User `gorm:"many2many:rel_team_snapshot_member"` }
func (*TeamSnapshot) Delete ¶
func (ts *TeamSnapshot) Delete(db *gorm.DB)
func (*TeamSnapshot) GetMembers ¶
func (ts *TeamSnapshot) GetMembers(db *gorm.DB) []User
type User ¶
type User struct { gorm.Model Username string `gorm:"size:20;unique;not null"` PasswordHash string `gorm:"not null"` Email string `gorm:"size:100"` Profile *UserProfile IsAdmin bool IsHidden bool IsBanned bool DefaultTeam uint AsContestAdmin []*Contest `gorm:"many2many:rel_contest_admin"` AsTeamAdmin []*Team `gorm:"many2many:rel_team_admin"` SolvedProblems []*Problem `gorm:"many2many:rel_problem_solver"` UnlockedHints []*Hint `gorm:"many2many:rel_user_unlocked_hint"` Submissions []*Submission `gorm:"foreignkey:CreatorID"` CreatedContests []*Contest `gorm:"foreignkey:CreatorID"` CreatedProblems []*Problem `gorm:"foreignkey:CreatorID"` CreatedTeams []*Team `gorm:"foreignkey:CreatorID"` CreatedResources []*Resource `gorm:"foreignkey:CreatorID"` Teams []*Team `gorm:"many2many:rel_user_team"` TeamSnapshots []*TeamSnapshot `gorm:"many2many:rel_team_snapshot_member"` }
func GetUsersWithQuery ¶
func (*User) CalcPersonalContestPoints ¶
func (*User) CalcTeamContestPoints ¶
func (*User) GetContestTeam ¶
func (*User) GetSolvedProblems ¶
Get associations
func (*User) IsContestAdmin ¶
Permission check
func (*User) IsResourceAdmin ¶
Click to show internal directories.
Click to hide internal directories.