users

package
v0.0.0-...-39e0c7e Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2022 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Samples

func Samples() error

func SetDB

func SetDB(database database.Database)

Types

type Scope

type Scope string
const (
	FullAdmin   Scope = "admin"
	ReadOnly    Scope = "readonly"
	RServices   Scope = "read:services"
	RWServices  Scope = "write:services"
	RIncidents  Scope = "read:incidents"
	RWIncidents Scope = "write:incidents"

	EmptyUser Scope = "none"
)

type User

type User struct {
	Id        int64         `gorm:"primary_key;column:id" json:"id"`
	Username  string        `gorm:"type:varchar(100);unique;column:username;" json:"username,omitempty"`
	Password  string        `gorm:"column:password" json:"password,omitempty"`
	Email     string        `gorm:"type:varchar(100);column:email" json:"email,omitempty"`
	ApiKey    string        `gorm:"column:api_key" json:"api_key,omitempty"`
	Scopes    string        `gorm:"column:scopes" json:"scopes,omitempty"`
	Admin     null.NullBool `gorm:"column:administrator" json:"admin,omitempty"`
	CreatedAt time.Time     `gorm:"column:created_at" json:"created_at"`
	UpdatedAt time.Time     `gorm:"column:updated_at" json:"updated_at"`
	Token     string        `gorm:"-" json:"token"`
}

User is the main struct for Users

func All

func All() []*User

func AuthUser

func AuthUser(username, passwordHash string) (*User, bool)

AuthUser will return the User and a boolean if authentication was correct. accepts username, and password as a string

func Find

func Find(id int64) (*User, error)

func FindByAPIKey

func FindByAPIKey(key string) (*User, error)

func FindByUsername

func FindByUsername(username string) (*User, error)

func (*User) AfterCreate

func (u *User) AfterCreate()

func (*User) AfterDelete

func (u *User) AfterDelete()

func (*User) AfterFind

func (u *User) AfterFind()

func (*User) AfterUpdate

func (u *User) AfterUpdate()

func (*User) AllScopes

func (u *User) AllScopes() []Scope

func (*User) BeforeCreate

func (u *User) BeforeCreate() error

func (*User) BeforeDelete

func (u *User) BeforeDelete() error

func (*User) BeforeUpdate

func (u *User) BeforeUpdate() error

func (*User) Create

func (u *User) Create() error

func (*User) Delete

func (u *User) Delete() error

func (*User) Update

func (u *User) Update() error

func (*User) Validate

func (u *User) Validate() error

Jump to

Keyboard shortcuts

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