model

package
v0.0.0-...-c391c35 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2016 License: MIT Imports: 16 Imported by: 0

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

View Source
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.

func LastPlanJSON

func LastPlanJSON() string

LastPlanJSON returns the last plan in JSON format.

Types

type Part

type Part struct {
	Day           time.Time
	Substitutions []Substitution
}

Part represents the list of substitutions for one day.

type Plan

type Plan struct {
	Created time.Time
	Parts   []Part
}

Plan represents the substitution's plan file with both parts.

func ToPlan

func ToPlan(uploadReader io.Reader) (*Plan, error)

func (*Plan) Create

func (plan *Plan) Create(file []byte)

Create saves this plan to the database as the newest plan.

type Session

type Session struct {
	Id         string
	Username   string
	Expiration time.Time
}

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

func (*SessionStore) Session

func (store *SessionStore) Session(sid string) (Session, bool)

type Subject

type Subject struct {
	Short      string
	Name       string
	SplitClass bool
}

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) Delete

func (s *Subject) Delete()

Delete removes this subject from the database.

func (*Subject) Exists

func (s *Subject) Exists() bool

Exists tells whether there is a subject record with this subject's short.

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

func (s *Subject) UpdateShort(short string)

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

type Teacher struct {
	Short string
	Name  string
	Sex   string
}

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) Delete

func (t *Teacher) Delete()

Delete removes this teacher from the database.

func (*Teacher) Exists

func (t *Teacher) Exists() bool

Exists tells whether there is a teacher record with this teacher's short.

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

func (t *Teacher) UpdateShort(short string)

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

type User struct {
	ID       uint
	Name     string
	Password string
}

User represents a user associating his identification and authentification information.

func (*User) Create

func (u *User) Create(password string)

Create inserts this new user into the database. The user receiver should only convey the name of this new user.

func (*User) Delete

func (u *User) Delete()

Delete removes this user from the database.

func (*User) Exists

func (u *User) Exists() bool

UsernameTaken returns true if the username is already in use and therefore can't be taken by a second user.

func (*User) GetWithPassword

func (u *User) GetWithPassword(password string) error

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

func (u *User) UpdatePassword(password string)

UpdatePassword saves the new password (hash) into the existing user's entry. This method hashes the password properly.

Jump to

Keyboard shortcuts

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