model

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var All = []any{
	User{},
	Key{},
	Server{},
	Grant{},
	Token{},
}
View Source
var UserIDPattern = regexp.MustCompile(`^[a-z][a-z0-9\._\-]{3,}$`)

UserIDPattern general name pattern

Functions

func CreateUserPassword

func CreateUserPassword(p string) (string, error)

Types

type Grant

type Grant struct {
	ID         string    `gorm:"column:id;primaryKey" json:"id"`
	UserID     string    `gorm:"column:user_id;index" json:"user_id"`
	ServerUser string    `gorm:"column:server_user;index" json:"server_user"`
	ServerID   string    `gorm:"column:server_id;index" json:"server_id"`
	CreatedAt  time.Time `gorm:"column:created_at;index" json:"created_at"`

	User User
}

type Key

type Key struct {
	// sha256 of public key
	ID          string `gorm:"column:id;primarykey" json:"id"`
	DisplayName string `gorm:"column:display_name" json:"display_name"`
	UserID      string `gorm:"column:user_id;index" json:"user_id"`
	User        User
	CreatedAt   time.Time `gorm:"column:created_at;index" json:"created_at"`
}

type Server

type Server struct {
	ID        string    `gorm:"column:id;primaryKey" json:"id"`
	Address   string    `gorm:"column:address" json:"address"`
	CreatedAt time.Time `gorm:"column:created_at;index" json:"created_at"`
}

type Token

type Token struct {
	ID        string    `gorm:"column:id;primarykey" json:"id"`
	UserID    string    `gorm:"column:user_id;not null;index" json:"user_id"`
	CreatedAt time.Time `gorm:"column:created_at;not null;index" json:"created_at"`
	VisitedAt time.Time `gorm:"column:visited_at;not null;index" json:"visited_at"`
	UserAgent string    `gorm:"column:user_agent;not null" json:"user_agent"`

	User User `json:"-"`
}

type User

type User struct {
	ID             string    `gorm:"column:id;primarykey" json:"id"`
	PasswordDigest string    `gorm:"column:password_digest;not null" json:"-"`
	CreatedAt      time.Time `gorm:"column:created_at;not null;index" json:"created_at"`
	VisitedAt      time.Time `gorm:"column:visited_at;not null;index" json:"visited_at"`
	IsAdmin        bool      `gorm:"column:is_admin;not null;default:0;index" json:"is_admin"`
	IsBlocked      bool      `gorm:"column:is_blocked;not null;default:0;index" json:"is_blocked"`

	Keys   []Key   `json:"keys,omitempty"`
	Grants []Grant `json:"grants,omitempty"`
	Tokens []Token `json:"tokens,omitempty"`
}

func (*User) CheckPassword

func (u *User) CheckPassword(p string) bool

CheckPassword check password

func (*User) SetPassword

func (u *User) SetPassword(p string) (err error)

SetPassword update password for user bcrypt produces clear text encrypted password, no further encoding needed

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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