models

package
v0.0.0-...-8c61d13 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connection

func Connection(c *Config) string

Connection creates the connection string and returns it.

Types

type Bookmark

type Bookmark struct {
	gorm.Model  `json:"-"`
	EntityID    uint   `json:"-"`
	Archived    bool   `json:"archived"`
	Description string `json:"description" gorm:"size:500"`
	URL         string `json:"url" gorm:"size:1000"`
	FaviconURL  string `json:"favicon_url"`
	Content     string `json:"content"`
}

type Config

type Config struct {
	Domain  string `json:"domain"`
	WebRoot string `json:"web_root"`
	BaseURL string `json:"base_url"`
	UseSSL  bool   `json:"use_ssl"`
	DB      struct {
		User     string `json:"user"`
		Password string `json:"password"`
		Host     string `json:"host"`
		Database string `json:"database"`
	} `json:"db"`
	Server struct {
		Port int `json:"port"`
	} `json:"server"`
	Security struct {
		Jwt struct {
			Secret string `json:"secret"`
		} `json:"jwt"`
		TwoFA struct {
			Secret string `json:"secret"`
		} `json:"2fa"`
	} `json:"security"`
}

Config represents the structure of the config.json file.

func (*Config) Init

func (c *Config) Init(p string)

Init reads the config.json file by the provided path and creates an Config instance.

func (*Config) SetURL

func (c *Config) SetURL()

SetURL sets all URLs based on the config's domain

type DB

type DB struct {
	Conn *gorm.DB
}

DB is the top-level Database instance.

func (*DB) CheckTemp2FAToken

func (d *DB) CheckTemp2FAToken(t string) bool

CheckTemp2FAToken checks the temp 2FA token and its expiration timestamp

func (*DB) DefaultSettings

func (d *DB) DefaultSettings() Settings

func (*DB) GetBookmarksByUserID

func (d *DB) GetBookmarksByUserID(id uint) []Bookmark

func (*DB) GetFolders

func (d *DB) GetFolders(id uint) []Folder

func (*DB) GetSubEntities

func (d *DB) GetSubEntities(hash string, id uint) []Folder

func (*DB) GetSubFolders

func (d *DB) GetSubFolders(hash string, id uint) []Folder

func (*DB) Init

func (d *DB) Init(c *Config)

Init sets up the Database connection. This function will panic if the connection isn't possible.

func (*DB) LoadSettings

func (d *DB) LoadSettings() Settings

func (*DB) Register

func (d *DB) Register(user, pass, last, first, mail string) error

func (*DB) SaveBookmark

func (d *DB) SaveBookmark(b Bookmark)

func (*DB) SaveBookmarkToFolder

func (d *DB) SaveBookmarkToFolder(parentHash string, b Bookmark) error

func (*DB) SaveFolder

func (d *DB) SaveFolder(f Folder)

func (*DB) SaveSubFolder

func (d *DB) SaveSubFolder(parentHash string, sub Folder) error

func (*DB) SetTemp2FAToken

func (d *DB) SetTemp2FAToken(u *User, t string, expirationTime time.Time) error

SetTempTwoFAToken sets a temp 2FA token and its expiration timestamp

func (*DB) Update2FA

func (d *DB) Update2FA(username, key string) error

func (*DB) ValidateCredentials

func (d *DB) ValidateCredentials(username, inputPass string) (bool, User)

func (*DB) ValidateNewCredentials

func (d *DB) ValidateNewCredentials(u, p string) bool

type DBModel

type DBModel struct {
}

type Entity

type Entity struct {
	gorm.Model `json:"-"`
	OwnerID    uint       `json:"-"`
	Type       string     `json:"type"`
	Hash       string     `json:"hash"`
	Name       string     `json:"name"`
	Pinned     bool       `json:"pinned"`
	ImageURL   string     `json:"image_url"`
	Bookmark   *Bookmark  `json:"bookmark"`
	Folder     *Folder    `json:"folder"`
	Note       *Note      `json:"note"`
	HasParent  bool       `json:"has_parent"`
	ShareHash  string     `json:"share_hash"`
	ShareUntil *time.Time `json:"share_until"`
	ShareTimes uint       `json:"share_times"`
}

type EntityRelation

type EntityRelation struct {
	ID       uint   `json:"id" gorm:"UNIQUE;AUTO_INCREMENT"`
	ParentID uint   `json:"parent_id"`
	ChildID  uint   `json:"child_id"`
	Type     string `type`
}

type Folder

type Folder struct {
	gorm.Model    `json:"-"`
	EntityID      uint `json:"-"`
	ChildrenCount uint `json:"children_count"`
	HasParent     bool `json:"has_parent"`
}

type Group

type Group struct {
}

type Note

type Note struct {
	gorm.Model `json:"-"`
	EntityID   uint   `json:"-"`
	Content    string `json:"content" gorm:"size:20000"`
}

type Role

type Role int
const (
	Admin Role = iota
	Normal
)

func (Role) String

func (r Role) String() string

type Settings

type Settings struct {
	gorm.Model
	RegisterEnabled bool `json:"register_enabled"`
	SharingEnabled  bool `json:"sharing_enabled"`
}

type Tag

type Tag struct {
	gorm.Model `json:"-"`
	OwnerID    uint   `owner_id`
	Hash       string `json:"hash"`
	Name       string `json:"name"`
}

type User

type User struct {
	gorm.Model
	Username           string     `json:"username"`
	Password           string     `json:"password"`
	Role               Role       `json:"role"`
	Firstname          string     `json:"firstname"`
	Lastname           string     `json:"lastname"`
	EMail              string     `json:"email"`
	TwoFA              bool       `json:"-"`
	TwoFAKey           string     `json:"-"`
	TempTwoFAToken     string     `json:"-"`
	TempTwoFATokenDate *time.Time `json:"-"`
}

Jump to

Keyboard shortcuts

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