wiki

package
v0.0.0-...-e682752 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2023 License: MPL-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntPref = iota
	TextPref
	SelectionPref
)

Variables

View Source
var ErrArticleNotModified = errors.New("article not modified")
View Source
var ErrBadUsername = errors.New("username must only contain letters, numbers, -, or _")
View Source
var ErrEmailTaken = errors.New("email already in use")
View Source
var ErrEmptyUsername = errors.New("username cannot be empty")
View Source
var ErrGenericNotFound = errors.New("not found")
View Source
var ErrIncorrectPassword = errors.New("incorrect password")
View Source
var ErrPasswordTooShort = errors.New("password too short")
View Source
var ErrRevisionAlreadyExists = errors.New("revision already exists")
View Source
var ErrRevisionNotFound = errors.New("revision not found")
View Source
var ErrUsernameNotFound = errors.New("username not found")
View Source
var ErrUsernameTaken = errors.New("username already in use")

Functions

This section is empty.

Types

type Article

type Article struct {
	URL string
	*Revision
}

func NewArticle

func NewArticle(url, title, markdownBody string) *Article

func (*Article) String

func (article *Article) String() string

type Config

type Config struct {
	CookieSecret          []byte `yaml:"-"`
	CookieExpiry          int    `yaml:"cookie_expiry"`
	DatabaseFile          string `yaml:"dbfile"`
	MinimumPasswordLength int    `yaml:"minimum_password_length"`
	Host                  string `yaml:"host"`
}

type ContextKey

type ContextKey string
const UserKey ContextKey = "periwiki.user"

UserKey is for context.Context

type Preference

type Preference struct {
	ID               int            `db:"id"`
	Label            string         `db:"pref_label"`
	Type             int            `db:"pref_type"`
	HelpText         sql.NullString `db:"help_text"`
	IntValue         sql.NullInt64  `db:"pref_int"`
	TextValue        sql.NullString `db:"pref_text"`
	SelectionValue   sql.NullInt64  `db:"pref_selection"`
	SelectionChoices []*PreferenceSelection
}

type PreferenceSelection

type PreferenceSelection struct {
	PreferenceID int    `db:"pref_id"`
	Value        int    `db:"val"`
	Label        string `db:"pref_selection_label"`
}

type Revision

type Revision struct {
	ID         int    `db:"id"`
	Title      string `db:"title"`
	Markdown   string `db:"markdown"`
	HTML       string `db:"html"`
	Hash       string `db:"hashval"`
	Creator    *User
	Created    time.Time `db:"created"`
	PreviousID int       `db:"previous_id"`
	Comment    string    `db:"comment"`
}

type User

type User struct {
	Email        string `db:"email"`
	ScreenName   string `db:"screenname"`
	ID           int    `db:"id"`
	PasswordHash string `db:"passwordhash"`
	RawPassword  string
	IPAddress    string
}

func AnonymousUser

func AnonymousUser() *User

func (*User) SetPasswordHash

func (u *User) SetPasswordHash() error

type WikiModel

type WikiModel struct {
	*Config
	// contains filtered or unexported fields
}

func New

func New(db db, conf *Config, s *bluemonday.Policy) *WikiModel

func (*WikiModel) CheckUserPassword

func (model *WikiModel) CheckUserPassword(u *User) error

func (*WikiModel) DeleteCookie

func (model *WikiModel) DeleteCookie(r *http.Request, rw http.ResponseWriter, s *sessions.Session) error

DeleteCookie wraps gorilla/sessions.Store.Delete, as implemented by WikiModel.db

func (*WikiModel) GetArticle

func (model *WikiModel) GetArticle(url string) (*Article, error)

func (*WikiModel) GetArticleByRevisionHash

func (model *WikiModel) GetArticleByRevisionHash(url string, hash string) (*Article, error)

func (*WikiModel) GetArticleByRevisionID

func (model *WikiModel) GetArticleByRevisionID(url string, id int) (*Article, error)

func (*WikiModel) GetCookie

func (model *WikiModel) GetCookie(r *http.Request, name string) (*sessions.Session, error)

GetCookie wraps gorilla/sessions.Store.Get, as implemented by WikiModel.db

func (*WikiModel) GetPreference

func (model *WikiModel) GetPreference(key string) (*Preference, error)

func (*WikiModel) GetRevisionHistory

func (model *WikiModel) GetRevisionHistory(url string) ([]*Revision, error)

func (*WikiModel) GetUserByScreenName

func (model *WikiModel) GetUserByScreenName(screenname string) (*User, error)

func (*WikiModel) NewCookie

func (model *WikiModel) NewCookie(r *http.Request, name string) (*sessions.Session, error)

NewCookie wraps gorilla/sessions.Store.New, as implemented by WikiModel.db

func (*WikiModel) PostArticle

func (model *WikiModel) PostArticle(article *Article) error

func (*WikiModel) PostUser

func (model *WikiModel) PostUser(user *User) error

PostUser inserts attempts to insert a user into the database

func (*WikiModel) PreviewMarkdown

func (model *WikiModel) PreviewMarkdown(markdown string) (string, error)

func (*WikiModel) Render

func (model *WikiModel) Render(markdown string) (string, error)

func (*WikiModel) SaveCookie

func (model *WikiModel) SaveCookie(r *http.Request, rw http.ResponseWriter, s *sessions.Session) error

SaveCookie wraps gorilla/sessions.Store.Save, as implemented by WikiModel.db

func (*WikiModel) UpdatePreference

func (model *WikiModel) UpdatePreference(pref *Preference) error

Jump to

Keyboard shortcuts

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