Documentation ¶
Index ¶
- Constants
- Variables
- func DeleteEmailToken(token EmailToken) error
- func GetDataForSchool(school *School, user *User) (map[string]interface{}, error)
- func SaveEmailToken(token EmailToken) error
- func UserExistsWithEmail(email string) (bool, int, error)
- type Application
- type ApplicationAuthorization
- type DetailedSchoolError
- type EmailToken
- type EmailTokenType
- type Event
- type EventAction
- type EventChange
- type EventTagType
- type Feedback
- type Homework
- type HomeworkClass
- type OffBlock
- type PlannerAnnouncement
- type PlannerFriday
- type Pref
- type Prefix
- type Provider
- type ProviderData
- type ProviderDataType
- type RecurFrequency
- type RecurRule
- type School
- type SchoolError
- type SchoolInfo
- type SchoolRegistry
- type SchoolResult
- type Tab
- type User
Constants ¶
const ( AnnouncementTypeText = 0 // just informative AnnouncementTypeFullOff = 1 // no classes at all AnnouncementTypeBreakStart = 2 // start of a break (inclusive of that day!) AnnouncementTypeBreakEnd = 3 // end of a break (exclusive of that day!) )
The available announcement types.
const ( ProviderDataAnnouncements = (1 << 0) ProviderDataEvents = (1 << 1) ProviderDataAll = ProviderDataAnnouncements | ProviderDataEvents )
const FallbackBackground = "FFD3BD"
FallbackBackground is the background color of a word that does not have an associated prefix.
const FallbackColor = "000000"
FallbackColor is the text color of a word that does not have an associated prefix.
Variables ¶
var DB *sql.DB
var DefaultPrefixes = []Prefix{ { ID: -1, Background: "4C6C9B", Color: "FFFFFF", Words: []string{"HW", "Read", "Reading"}, Default: true, }, { ID: -1, Background: "9ACD32", Color: "FFFFFF", Words: []string{"Project"}, Default: true, }, { ID: -1, Background: "C3A528", Color: "FFFFFF", Words: []string{"Report", "Essay", "Paper", "Write"}, Default: true, }, { ID: -1, Background: "FFA500", Color: "FFFFFF", Words: []string{"Quiz", "PopQuiz", "GradedHW", "GradedHomework"}, Default: true, }, { ID: -1, Background: "EE5D1E", Color: "FFFFFF", Words: []string{"Quest"}, Default: true, }, { ID: -1, Background: "DC143C", Color: "FFFFFF", Words: []string{"Test", "Final", "Exam", "Midterm"}, Default: true, }, { ID: -1, Background: "2AC0F1", Color: "FFFFFF", Words: []string{"ICA", "FieldTrip"}, Default: true, }, { ID: -1, Background: "2AF15E", Color: "FFFFFF", Words: []string{"Study", "Memorize"}, TimedEvent: true, Default: true, }, { ID: -1, Background: "000000", Color: "00FF00", Words: []string{"Trojun", "Hex"}, Default: true, }, { ID: -1, Background: "5000BC", Color: "FFFFFF", Words: []string{"OptionalHW", "Challenge"}, Default: true, }, { ID: -1, Background: "000099", Color: "FFFFFF", Words: []string{"Presentation", "Prez"}, Default: true, }, { ID: -1, Background: "123456", Color: "FFFFFF", Words: []string{"BuildSession", "Build"}, TimedEvent: true, Default: true, }, { ID: -1, Background: "5A1B87", Color: "FFFFFF", Words: []string{"Meeting", "Meet"}, TimedEvent: true, Default: true, }, { ID: -1, Background: "01B501", Color: "FFFFFF", Words: []string{"Begin", "Start", "Do"}, TimedEvent: true, Default: true, }, { ID: -1, Background: "E34000", Color: "FFFFFF", Words: []string{"Apply", "Application", "Deadline"}, Default: true, }, { ID: -1, Background: "3F4146", Color: "FFFFFF", Words: []string{"Form", "File", "Submit", "Upload"}, Default: true, }, }
DefaultPrefixes is the list of prefixes that all users start out with.
var (
ErrNotFound = errors.New("data: not found")
)
var RedisClient *redis.Client
Functions ¶
func DeleteEmailToken ¶
func DeleteEmailToken(token EmailToken) error
DeleteEmailToken deletes the given email token.
func GetDataForSchool ¶
GetDataForSchool returns the data associated with the User's enrollment in the given School.
func SaveEmailToken ¶
func SaveEmailToken(token EmailToken) error
SaveEmailToken saves the given email token with a default expiry.
Types ¶
type Application ¶
type Application struct { ID int `json:"id"` Name string `json:"name"` AuthorName string `json:"authorName"` ClientID string `json:"clientId"` CallbackURL string `json:"callbackUrl"` }
An Application describes a third-party application designed to integrate with MyHomeworkSpace.
type ApplicationAuthorization ¶
type ApplicationAuthorization struct { ID int `json:"id"` ApplicationID int `json:"applicationId"` Name string `json:"name"` AuthorName string `json:"authorName"` }
An ApplicationAuthorization describes a user's authorization of an application's access to their account.
type DetailedSchoolError ¶
DetailedSchoolError is a type of Error that occurs when a school provider wants to communicate data back to the client along with an error. This is useful for multi-step enrollments, where more information is required from the user.
func (DetailedSchoolError) Error ¶
func (e DetailedSchoolError) Error() string
type EmailToken ¶
type EmailToken struct { Token string `json:"token"` Type EmailTokenType `json:"type"` Metadata string `json:"metadata"` UserID int `json:"userID"` }
An EmailToken is used for situations like an email change or a password reset, where a confirmation email must be sent.
func GetEmailToken ¶
func GetEmailToken(token string) (EmailToken, error)
GetEmailToken fetches the given email token.
type EmailTokenType ¶
type EmailTokenType int
An EmailTokenType describes different types of email token
const ( EmailTokenNone EmailTokenType = iota EmailTokenResetPassword EmailTokenChangeEmail EmailTokenVerifyEmail )
Define the default EmailTokenType.
type Event ¶
type Event struct { ID int `json:"id"` UniqueID string `json:"uniqueId"` SeriesID string `json:"seriesId"` SeriesName string `json:"seriesName"` Name string `json:"name"` Start int `json:"start"` End int `json:"end"` StartTimezone string `json:"startTimezone"` EndTimezone string `json:"endTimezone"` RecurRule *RecurRule `json:"recurRule"` Tags map[EventTagType]interface{} `json:"tags"` Source int `json:"source"` UserID int `json:"userId"` }
An Event is an event on a user's calendar. It could be from their schedule, homework, or manually added.
type EventAction ¶
type EventAction struct { Icon string `json:"icon"` Name string `json:"name"` URL string `json:"url"` }
An EventAction is an action that can be performed on an Event; for example, a link to open a class's website.
type EventChange ¶
type EventChange struct { EventID string `json:"eventID"` Cancel bool `json:"cancel"` UserID int `json:"userID"` }
An EventChange is a modification a user makes to an Event that came from a provider.
type EventTagType ¶
type EventTagType int
An EventTagType describes the type of an event tag.
const ( EventTagReserved EventTagType = iota EventTagDescription EventTagHomework EventTagTermID EventTagClassID EventTagOwnerID EventTagOwnerName EventTagDayNumber EventTagBlock EventTagBuildingName EventTagRoomNumber EventTagLocation EventTagReadOnly EventTagShortName EventTagActions EventTagCancelled EventTagCancelable EventTagSection EventTagOriginalStart EventTagOriginalEnd EventTagHideBuildingName EventTagHomeworkClass EventTagInstanceStart EventTagInstanceEnd EventTagIsContinuation EventTagContinues )
The available event tags.
type Feedback ¶
type Feedback struct { ID int `json:"id"` UserID int `json:"userid"` Type string `json:"type"` Text string `json:"text"` Timestamp string `json:"timestamp"` UserName string `json:"userName"` UserEmail string `json:"userEmail"` HasScreenshot bool `json:"hasScreenshot"` UserAgent string `json:"userAgent"` }
type HomeworkClass ¶
type HomeworkClass struct { ID int `json:"id"` Name string `json:"name"` Teacher string `json:"teacher"` Color string `json:"color"` SortIndex int `json:"sortIndex"` UserID int `json:"userId"` }
A HomeworkClass is a class that can be associated with Homework items.
func GetClassesForUser ¶
func GetClassesForUser(user *User) ([]HomeworkClass, error)
GetClassesForUser gets all HomeworkClasses for the given user.
type OffBlock ¶
type OffBlock struct { StartID int `json:"startId"` EndID int `json:"endId"` Start time.Time `json:"-"` End time.Time `json:"-"` StartText string `json:"start"` EndText string `json:"end"` Name string `json:"name"` Grade int `json:"grade"` }
An OffBlock is a period of time that's marked off on a calendar, such as a holiday.
type PlannerAnnouncement ¶
type PlannerFriday ¶
type Prefix ¶
type Prefix struct { ID int `json:"id"` Background string `json:"background"` Color string `json:"color"` Words []string `json:"words"` TimedEvent bool `json:"timedEvent"` Default bool `json:"default"` }
A Prefix defines a group of words that get automatically recognized (for example: HW, Test, Quiz)
func GetPrefixesForUser ¶
GetPrefixesForUser returns a list of all prefixes for the given user, factoring in schools and custom settings.
type Provider ¶
type Provider interface { ID() string Name() string GetData(db *sql.DB, user *User, location *time.Location, startTime time.Time, endTime time.Time, dataType ProviderDataType) (ProviderData, error) }
A Provider is a source of calendar data (events, announcements, etc)
type ProviderData ¶
type ProviderData struct { Announcements []PlannerAnnouncement `json:"announcements"` Events []Event `json:"events"` }
A ProviderData struct contains all data returned by a Provider for a given time
type ProviderDataType ¶
type ProviderDataType uint8
ProviderDataType describes the different types of data that can be requested from a Provider.
type RecurFrequency ¶
type RecurFrequency int
A RecurFrequency describes how often an event recurs.
const ( RecurFrequencyDaily RecurFrequency = iota RecurFrequencyWeekly RecurFrequencyMonthly RecurFrequencyYearly )
Define the default RecurFrequencies.
type RecurRule ¶
type RecurRule struct { ID int `json:"id"` EventID int `json:"eventId"` Frequency RecurFrequency `json:"frequency"` Interval int `json:"interval"` ByDayString string `json:"-"` ByDay []time.Weekday `json:"byDay"` ByMonthDay int `json:"byMonthDay"` ByMonth time.Month `json:"byMonth"` Until string `json:"until"` }
A RecurRule struct contains information about how an event recurs. Inspired by the iCal RRULE system.
type School ¶
type School interface { ID() string Name() string ShortName() string UserDetails() string EmailAddress() string EmailDomain() string Prefixes() []Prefix CalendarProvider() Provider Hydrate(data map[string]interface{}) error CallSettingsMethod(db *sql.DB, user *User, methodName string, methodParams map[string]interface{}) (map[string]interface{}, error) GetSettings(db *sql.DB, user *User) (map[string]interface{}, error) SetSettings(db *sql.DB, user *User, settings map[string]interface{}) (*sql.Tx, map[string]interface{}, error) Enroll(tx *sql.Tx, user *User, params map[string]interface{}) (map[string]interface{}, error) Unenroll(tx *sql.Tx, user *User) error NeedsUpdate(db *sql.DB) (bool, error) }
School is an interface implemented by all schools that a user can connect to their account
func GetSchoolsForUser ¶
GetSchoolsForUser returns a list of schools that the given user is enrolled in, excluding disabled schools.
type SchoolError ¶
type SchoolError struct {
Code string
}
SchoolError is a type of Error that occurs due to invalid data or a similar condition. It's used to distinguish from internal server errors.
func (SchoolError) Error ¶
func (e SchoolError) Error() string
type SchoolInfo ¶
type SchoolInfo struct { EnrollmentID int `json:"enrollmentID"` SchoolID string `json:"schoolID"` Enabled bool `json:"enabled"` DisplayName string `json:"displayName"` ShortName string `json:"shortName"` UserDetails string `json:"userDetails"` EmailAddress string `json:"emailAddress"` School School `json:"-"` UserID int `json:"userID"` }
SchoolInfo is a struct that holds information about a school. It's used to hold data in a format that the JSON package can then marshal out to the client.
type SchoolRegistry ¶
type SchoolRegistry interface { GetAllSchools() []School GetSchoolByEmailDomain(domain string) (School, error) GetSchoolByID(id string) (School, error) Register(school School) }
SchoolRegistry is an interface implemented by the central registry in the schools package
var MainRegistry SchoolRegistry
type SchoolResult ¶
type SchoolResult struct { SchoolID string `json:"schoolID"` DisplayName string `json:"displayName"` ShortName string `json:"shortName"` }
SchoolResult is a struct that holds information about a school that was searched for. (e.g. by email domain) It's used to hold data in a format that the JSON package can then marshal out to the client.
type Tab ¶
type Tab struct { ID int `json:"id"` Slug string `json:"slug"` Icon string `json:"icon"` Label string `json:"label"` Target string `json:"target"` }
func GetTabsByUserID ¶
GetTabsByUserID fetches all tabs that the given user has access to.
type User ¶
type User struct { ID int `json:"id"` Name string `json:"name"` Email string `json:"email"` PasswordHash string `json:"-"` Type string `json:"type"` Features string `json:"features"` Level int `json:"level"` EmailVerified bool `json:"emailVerified"` ShowMigrateMessage int `json:"showMigrateMessage"` CreatedAt int `json:"createdAt"` LastLoginAt int `json:"lastLoginAt"` Schools []SchoolInfo `json:"schools"` }
func GetUserByID ¶
GetUserByID fetches data for the given user ID.