Documentation ¶
Overview ¶
Package model provides access to the models and separates the database management from the business logic of adding new users for example. The models usually use the CRUD methods Create, Read, Update and Delete. See their documentation for particular information.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrNoSuchUser = errors.New("model: user not found") ErrNoMatchNamePassword = errors.New("model: wrong username or password") )
Errors returned by GetWithPassword. They should be used to tell what didn't work in the authentification.
Functions ¶
func CountUsers ¶
func CountUsers() int
CountUsers returns the total of recorded users in the database.
Types ¶
type Part ¶
type Part struct { Day time.Time Substitutions []Substitution }
Part represents the list of substitutions for one day.
type SessionStore ¶
type SessionStore struct { // CookieName is the name of the cookie containing the session's id. CookieName string // MaxAge is the duration the session is valid in seconds to be set with the cookie. MaxAge int sync.RWMutex // contains filtered or unexported fields }
var SStore *SessionStore
func (*SessionStore) DeleteSession ¶
func (store *SessionStore) DeleteSession(sid string)
func (*SessionStore) NewSession ¶
func (store *SessionStore) NewSession(user User) Session
type Subject ¶
Subject represents a subject associating abbreviations (short) with other subject information.
func ReadAllSubjects ¶
func ReadAllSubjects() []Subject
ReadAllSubjects fetches all subject records from the database and returns a slice with all subjects found.
func (*Subject) Create ¶
func (s *Subject) Create()
Create inserts this subject into the database. This only happens if there isn't an entry with this subject's short already. Otherwise nothing happens.
func (*Subject) Read ¶
func (s *Subject) Read()
Read completes this subject with the subject information associated with this subject's short.
func (*Subject) Update ¶
func (s *Subject) Update()
Update updates the subject record with the same short as this subject's short with the new data. To change the short itself, use UpdateShort.
func (*Subject) UpdateShort ¶
UpdateShort updates the subject identified by the given short with the data included in the given subject receiver.
type Substitution ¶
type Substitution struct { Period string Class string SubstTeacher Teacher InstdTeacher Teacher InstdSubject Subject Kind string Text string TaskProvider Teacher }
Substitutions represents the substitution's information.
type Teacher ¶
Teacher represents a teacher associating abbreviations (short) with name and compellation information.
func ReadAllTeachers ¶
func ReadAllTeachers() []Teacher
ReadAllTeachers fetches all teacher records from the database and returns a slice with all teachers found.
func (*Teacher) Create ¶
func (t *Teacher) Create()
Create inserts this teacher into the database. This only happens if there isn't an entry with this teacher's short already. Otherwise nothing happens.
func (*Teacher) Read ¶
func (t *Teacher) Read()
Read completes this teacher with the teacher information associated with this teacher's short.
func (*Teacher) Update ¶
func (t *Teacher) Update()
Update updates the teacher record with the same short as this teacher's short with the new data. To change the short itself, use UpdateShort.
func (*Teacher) UpdateShort ¶
UpdateShort updates the teacher identified by the given short with the data included in the given teacher receiver.
type UnknownSubject ¶
type UnknownSubject struct {
Short string
}
func ReadAllUnknownSubjects ¶
func ReadAllUnknownSubjects() []UnknownSubject
func (*UnknownSubject) Create ¶
func (us *UnknownSubject) Create()
func (*UnknownSubject) Delete ¶
func (us *UnknownSubject) Delete()
type UnknownTeacher ¶
type UnknownTeacher struct {
Short string
}
func ReadAllUnknownTeachers ¶
func ReadAllUnknownTeachers() []UnknownTeacher
func (*UnknownTeacher) Create ¶
func (ut *UnknownTeacher) Create()
func (*UnknownTeacher) Delete ¶
func (ut *UnknownTeacher) Delete()
type User ¶
User represents a user associating his identification and authentification information.
func (*User) Create ¶
Create inserts this new user into the database. The user receiver should only convey the name of this new user.
func (*User) Exists ¶
UsernameTaken returns true if the username is already in use and therefore can't be taken by a second user.
func (*User) GetWithPassword ¶
GetWithPassword finds out whether the given password matches the password of user. If these don't match an error is returned. This can be ErrNoMatchNamePassword, ErrNoSuchUser or an error indicating that something in the password hashing went wrong.
err := user.GetWithPassword(password) switch { case err == nil: // The user can get logged in or somthing. case err == model.ErrNoMatchNamePassword: // Maybe return a message to the user. case err == model.ErrNoSuchUser: // Maybe tell the user the username was wrong. default: // Some kind of internal error. }
func (*User) Read ¶
func (u *User) Read()
Read completes the user with the information associated with this user's name.
func (*User) Update ¶
func (u *User) Update()
Update saves this user (changes the information in the existing entry). The user should have been read before (with the Read method). For updating the password use UpdatePassword.
func (*User) UpdatePassword ¶
UpdatePassword saves the new password (hash) into the existing user's entry. This method hashes the password properly.