models

package
v0.0.0-...-a9a9e39 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LABEL_MIN_LENGTH   = 1
	LABEL_MAX_LENGTH   = 32
	TYPE_MIN_LENGTH    = 1
	TYPE_MAX_LENGTH    = 32
	SUBJECT_MIN_LENGTH = 1
	SUBJECT_MAX_LENGTH = 32
)
View Source
const (
	MaxImageSize = int64(6048 * 4032) // 24 megapixels, roughly 36MB as a raw image
)

Variables

View Source
var (
	IMAGE_EXTENSIONS = [7]string{".jpg", ".jpeg", ".gif", ".bmp", ".png", ".tiff", "tif"}
	IMAGE_MIME_TYPES = map[string]string{".jpg": "image/jpeg", ".jpeg": "image/jpeg", ".gif": "image/gif", ".bmp": "image/bmp", ".png": "image/png", ".tiff": "image/tiff", ".tif": "image/tif"}
)
View Source
var (
	ErrUsernameIllegal           = errors.New("User name contains illegal characters")
	ErrUsernameEmpty             = errors.New("Username cannot be empty")
	ErrUsernameReserved          = errors.New("Username is reserved")
	ErrUsernamePatternNotAllowed = errors.New("Pattern of username not allowed")
	ErrUserExists                = errors.New("A user with this username already exists")
	ErrFirstNameTooShort         = errors.New("models.user.first_name.too_short")
	ErrFirstNameTooLong          = errors.New("models.user.first_name.too_long")
	ErrLastNameTooShort          = errors.New("models.user.last_name.too_short")
	ErrLastNameTooLong           = errors.New("models.user.last_name.too_long")
	ErrPasswordTooWeak           = errors.New("Password does not meet requirements")
)

Functions

func GenPassword

func GenPassword() string

func GetImageMimeType

func GetImageMimeType(ext string) string

func GetUserSalt

func GetUserSalt() (string, error)

GetUserSalt generates a random string to use for salting passwords

func HashPassword

func HashPassword(passwd string, salt string) string

func IsComplexEnough

func IsComplexEnough(pwd string) bool

IsComplexEnough checks if a given password meets the required complexity

func IsFileExtImage

func IsFileExtImage(ext string) bool

func IsValidUsername

func IsValidUsername(s string) bool

Types

type Course

type Course struct {
	ID            string    `json:"id,omitempty" bson:"_id,omitempty"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
	Label         string    `bson:"label"`
	Type          string    `bson:"type"`
	Subject       string    `bson:"subject"`
	StudentIDs    []string  `bson:"studentIds"`
	InstructorIDs []string  `bson:"instructorIds"`
}

func (*Course) PreSave

func (c *Course) PreSave()

func (*Course) Validate

func (c *Course) Validate() error

type Error

type Error struct {
	ID         string
	Error      error
	Location   string
	StatusCode int
}

Error represents an internal error that may occur during a request

func NewError

func NewError(id, location string, err error, status int) *Error

NewError creates a new internal error

func (*Error) Message

func (e *Error) Message() string

Message returns the message of the internal error

type FileInfo

type FileInfo struct {
	ID        string `json:"id,omitempty" bson:"_id,omitempty"`
	Name      string `json:"name,omitempty"`
	Extension string `json:"extension,omitempty"`
	Directory string `json:"directory,omitempty"`
	Size      int    `json:"size,omitempty"`
	MimeType  string `json:"type,omitempty"`
}

func (*FileInfo) PreSave

func (fi *FileInfo) PreSave()

func (*FileInfo) Validate

func (fi *FileInfo) Validate() error

type LoginPayload

type LoginPayload struct {
	Token string
	User  *User
}

type Permissions

type Permissions struct {
	ManageUsers bool
	ManagePages bool
	ManagePosts bool
}

type Role

type Role struct {
	// The roles ID
	ID string `bson:"_id,omitempty"`
	// The name of the role
	Name string `bson:"name,omitempty"`
	// A short description of the role
	Description string `bson:"description,omitempty"`
	// The permissions the role has
	Permissions Permissions `bson:"permissions,omitempty"`
}

Role represents a users role that can have multiple permissions to access parts of the api and therefore can modify the websites content.

type User

type User struct {
	ID                string    `json:"id,omitempty" bson:"_id,omitempty"`
	CreatedAt         time.Time `json:"createdAt"`
	UpdatedAt         time.Time `json:"updatedAt"`
	Username          string    `json:"username,omitempty"`
	Email             string    `json:"email,omitempty"`
	EmailVerified     bool      `json:"emailVerified"`
	Password          string    `json:"password,omitempty"`
	PasswordUpdatedAt time.Time `json:"passwordUpdatedAt"`
	Salt              string    `json:"salt,omitempty"`
	Type              string    `json:"type,omitempty"`
	FirstName         string    `json:"firstName,omitempty"`
	LastName          string    `json:"lastName,omitempty"`
	LastLogin         time.Time `json:"lastLogin,omitempty"`
}

User represents a user that can be of type instructor, student, parent or staff. A user can access parts of the website or the admin section based on roles and permissions.

func (*User) FullName

func (u *User) FullName() string

FullName is a simple combination of the users first and last name.

func (*User) GetID

func (u *User) GetID() string

func (*User) PasswordValid

func (u *User) PasswordValid(passwd string) bool

PasswordValid validates a given password.

func (*User) Patch

func (u *User) Patch(patch *UserPatch)

func (*User) PreSave

func (u *User) PreSave()

func (*User) PreUpdate

func (u *User) PreUpdate()

func (*User) SetID

func (u *User) SetID(id string)

func (*User) SetPassword

func (u *User) SetPassword(passwd string)

SetPassword hashes the users password with a generated salt.

func (*User) SetPasswordSalt

func (u *User) SetPasswordSalt()

func (*User) Validate

func (u *User) Validate() error

type UserGetOptions

type UserGetOptions struct {
	Sort    string
	Page    int
	PerPage int
}

type UserPatch

type UserPatch struct {
	ID        string
	Email     *string
	FirstName *string
	LastName  *string
}

Jump to

Keyboard shortcuts

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