data

package
v0.0.0-...-9ebc2d1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2024 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallJWTAuth

func CallJWTAuth(db Datastore, userOnly bool, callback http.HandlerFunc) http.HandlerFunc

func CreateJWT

func CreateJWT(u *User) (string, error)

func GetLoginStatus

func GetLoginStatus(tokenStr string, r *http.Request, db Datastore) (string, error)

func ValiateClaims

func ValiateClaims(c jwt.Claims) (jwt.RegisteredClaims, bool)

func ValidateJWT

func ValidateJWT(tokenStr string) (*jwt.Token, error)

Types

type AccountReq

type AccountReq struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type Datastore

type Datastore interface {
	// Initalizers / Cleaners
	Close()
	CreateTables() error

	// Metadata
	EngineName() string
	Version() string

	// CRUD functions for page
	CreatePage(v *Page) error
	ReadPage(title string) (*Page, error)
	UpdatePage(p *Page, editor string) error
	DeletePage(title string) error

	// Small gets
	GetIdFromPageTitle(title string) (*int, error)
	GetUserIdFromName(username string) (*int64, error)
	GetUsernameFromId(id int64) (string, error)
	FetchPageHistory(title string) ([]PageEdit, error)

	// CRUD for user
	CreateUser(username string, password string) (*User, error)
	GetUser(username string) (*User, error)
	UpdateUser(u *User, newName string, newPass string) error
	DeleteUser(username string) error

	GetUserGroups(username string) ([]string, error)
	EditUserGroups(username string, changes RightsReq) error

	// CRUD for page edit
	CreatePageEdit(p *Page, editor string) error
	ReadPageEdit(id int64) (*PageEdit, error)
	DeletePageEdit(id int64) error

	// Search operations
	SearchPagesFromTitle(title string) ([]Page, error)
	SearchPagesFromTitlePrefix(prefix string, limit int) ([]Page, error)
	SearchPagesContainingTitle(title string, limit int) ([]Page, error)

	// Moderation actions
	GetLockStatus(p string) (int, error)
	LockPage(p string, min_group int) error
	UnlockPage(p string, min_group int) error

	IsSuspended(u string) (bool, error)
	SuspendUser(u string, duration int64) error
}

Created for use in future updates when we plan on implementing different databses

type LockReq

type LockReq struct {
	Title        string `json:"title"`
	MinimumGroup int64  `json:"minGroup"`
}

type Page

type Page struct {
	Title     string `json:"title"`
	Content   string `json:"content"`
	Namespace int    `json:"namespace"`
	MPType    int    `json:"mpType"`
}

type PageEdit

type PageEdit struct {
	EditId      int64     `pgx:"edit_id"     json:"editId"`
	PageId      int64     `pgx:"page_id"     json:"pageId"`
	Date        time.Time `pgx:"change_date" json:"changeDate"`
	Time        time.Time `pgx:"change_time" json:"changeTime"`
	UserId      string    `pgx:"editor"     json:"editor"`
	Description string    `pgx:"description" json:"description"`
	Content     string    `pgx:"content"     json:"content"`
}

func (PageEdit) MarshalJSON

func (pe PageEdit) MarshalJSON() ([]byte, error)

type PostgresBase

type PostgresBase struct {
	// contains filtered or unexported fields
}

func ConnectToPostgresDatabase

func ConnectToPostgresDatabase() (PostgresBase, error)

Postgres connections

func (*PostgresBase) Close

func (db *PostgresBase) Close()

func (*PostgresBase) CreatePage

func (db *PostgresBase) CreatePage(v *Page) error

func (*PostgresBase) CreatePageEdit

func (db *PostgresBase) CreatePageEdit(p *Page, editor string) error

Logs a page change into a diff.

func (*PostgresBase) CreateTables

func (db *PostgresBase) CreateTables() error

func (*PostgresBase) CreateUser

func (db *PostgresBase) CreateUser(username, password string) (*User, error)

func (*PostgresBase) DeletePage

func (db *PostgresBase) DeletePage(title string) error

func (*PostgresBase) DeletePageEdit

func (db *PostgresBase) DeletePageEdit(id int64) error

func (*PostgresBase) DeleteUser

func (db *PostgresBase) DeleteUser(username string) error

func (*PostgresBase) EditUserGroups

func (db *PostgresBase) EditUserGroups(username string, changes RightsReq) error

func (*PostgresBase) EngineName

func (db *PostgresBase) EngineName() string

Metadata

func (*PostgresBase) FetchPageHistory

func (db *PostgresBase) FetchPageHistory(title string) ([]PageEdit, error)

func (*PostgresBase) GetIdFromPageTitle

func (db *PostgresBase) GetIdFromPageTitle(title string) (*int, error)

Fetches page id from page title

func (*PostgresBase) GetLockStatus

func (db *PostgresBase) GetLockStatus(p string) (int, error)

func (*PostgresBase) GetUser

func (db *PostgresBase) GetUser(username string) (*User, error)

func (*PostgresBase) GetUserGroups

func (db *PostgresBase) GetUserGroups(username string) ([]string, error)

func (*PostgresBase) GetUserIdFromName

func (db *PostgresBase) GetUserIdFromName(username string) (*int64, error)

func (*PostgresBase) GetUsernameFromId

func (db *PostgresBase) GetUsernameFromId(id int64) (string, error)

func (*PostgresBase) IsSuspended

func (db *PostgresBase) IsSuspended(u string) (bool, error)

func (*PostgresBase) LockPage

func (db *PostgresBase) LockPage(p string, min_group int) error

func (*PostgresBase) ReadPage

func (db *PostgresBase) ReadPage(title string) (*Page, error)

func (*PostgresBase) ReadPageEdit

func (db *PostgresBase) ReadPageEdit(id int64) (*PageEdit, error)

func (*PostgresBase) SearchPagesContainingTitle

func (db *PostgresBase) SearchPagesContainingTitle(title string, limit int) ([]Page, error)

func (*PostgresBase) SearchPagesFromTitle

func (db *PostgresBase) SearchPagesFromTitle(title string) ([]Page, error)

Search operatons

func (*PostgresBase) SearchPagesFromTitlePrefix

func (db *PostgresBase) SearchPagesFromTitlePrefix(prefix string, limit int) ([]Page, error)

func (*PostgresBase) SuspendUser

func (db *PostgresBase) SuspendUser(u string, duration int64) error

func (*PostgresBase) UnlockPage

func (db *PostgresBase) UnlockPage(p string, min_group int) error

func (*PostgresBase) UpdatePage

func (db *PostgresBase) UpdatePage(p *Page, editor string) error

func (*PostgresBase) UpdateUser

func (db *PostgresBase) UpdateUser(u *User, newName, newPass string) error

func (*PostgresBase) Version

func (db *PostgresBase) Version() string

type RightsReq

type RightsReq struct {
	Add    []string
	Remove []string
}

type SusReq

type SusReq struct {
	Target   string `json:"target"`
	Duration int64  `json:"duration"`
}

type User

type User struct {
	UserId       int64
	Username     string
	Password     string
	CreationDate time.Time
}

func (*User) ValidPassword

func (u *User) ValidPassword(pw string) bool

type UserClaims

type UserClaims struct {
	UserID int64
	jwt.RegisteredClaims
}

Jump to

Keyboard shortcuts

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