users

package
v0.0.0-...-d1a9080 Latest Latest
Warning

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

Go to latest
Published: May 5, 2021 License: AGPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TableName is the user table name in database.
	TableName = "user"
)

Variables

View Source
var (
	// Users is the user manager.
	Users = Manager{}

	// ErrNotFound is returned when a user record was not found.
	ErrNotFound = errors.New("not found")
)

Functions

func AvailableGroups

func AvailableGroups() map[string]string

AvailableGroups returns the available group names. This is a mapping of ID => name.

func ValidGroups

func ValidGroups() []string

ValidGroups returns a list of available groups.

Types

type CreateForm

type CreateForm struct {
	Username string       `json:"username" conform:"trim"`
	Email    string       `json:"email" conform:"trim"`
	Group    *GroupChoice `json:"group" conform:"trim"`
	Password string       `json:"password"`
}

CreateForm describes a user creation form

func (*CreateForm) Validate

func (uf *CreateForm) Validate(f *form.Form)

Validate validates the form.

type GroupChoice

type GroupChoice string

func (*GroupChoice) Options

func (c *GroupChoice) Options() [][2]string

func (*GroupChoice) String

func (c *GroupChoice) String() string

func (*GroupChoice) Validate

func (c *GroupChoice) Validate(f *form.Field) error

type Manager

type Manager struct{}

Manager is a query helper for user entries.

func (*Manager) Create

func (m *Manager) Create(user *User) error

Create insert a new user in the database. The password must be present. It will be hashed and updated before insertion.

func (*Manager) GetOne

func (m *Manager) GetOne(expressions ...goqu.Expression) (*User, error)

GetOne executes the a select query and returns the first result or an error when there's no result.

func (*Manager) Query

func (m *Manager) Query() *goqu.SelectDataset

Query returns a prepared goqu SelectDataset that can be extended later.

type PasswordForm

type PasswordForm struct {
	Current  string `json:"current"`
	Password string `json:"password"`
}

PasswordForm is a form to update a user's password.

func (*PasswordForm) SetUser

func (pf *PasswordForm) SetUser(f *form.Form, u *User)

SetUser adds a user to the wrapping form's context.

func (*PasswordForm) Validate

func (pf *PasswordForm) Validate(f *form.Form)

Validate validates the form.

type ProfileForm

type ProfileForm struct {
	Username *string `json:"username" conform:"trim"`
	Email    *string `json:"email" conform:"trim"`
}

ProfileForm is the form used by the profile update routes.

func (*ProfileForm) Validate

func (sf *ProfileForm) Validate(f *form.Form)

Validate validates the form

type UpdateForm

type UpdateForm struct {
	Username *string       `json:"username" conform:"trim"`
	Email    *string       `json:"email" conform:"trim"`
	Group    *GroupChoice  `json:"group" conform:"trim"`
	Password *string       `json:"password"`
	Settings *UserSettings `json:"settings"`
}

UpdateForm describes a user update form.

func (*UpdateForm) SetUser

func (uf *UpdateForm) SetUser(f *form.Form, u *User)

SetUser adds a user to the wrapping form's context.

func (*UpdateForm) Validate

func (uf *UpdateForm) Validate(f *form.Form)

Validate validates the form

type User

type User struct {
	ID       int           `db:"id" goqu:"skipinsert,skipupdate"`
	Created  time.Time     `db:"created" goqu:"skipupdate"`
	Updated  time.Time     `db:"updated"`
	Username string        `db:"username"`
	Email    string        `db:"email"`
	Password string        `db:"password"`
	Group    string        `db:"group"`
	Settings *UserSettings `db:"settings"`
	Seed     int           `db:"seed"`
}

User is a user record in database

func (*User) CheckPassword

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

CheckPassword checks if the given password matches the current user password.

func (*User) Delete

func (u *User) Delete() error

Delete removes a user from the database

func (*User) HasPermission

func (u *User) HasPermission(obj, act string) bool

HasPermission returns true if the user can perform "act" action on "obj" object.

func (*User) HashPassword

func (u *User) HashPassword(password string) (string, error)

HashPassword returns a new hashed password

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

IsAnonymous returns true when the instance is not set to any existing user (when ID is 0)

func (*User) Roles

func (u *User) Roles() []string

Roles returns all the user's implicit roles.

func (*User) Save

func (u *User) Save() error

Save updates all the user values.

func (*User) SetPassword

func (u *User) SetPassword(password string) error

SetPassword set a new user password

func (*User) SetSeed

func (u *User) SetSeed() int

SetSeed sets a new seed to the user. It returns the seed as an integer value and does *not* save the data but the seed is accessible on the user instance.

func (*User) Update

func (u *User) Update(v interface{}) error

Update updates some user values.

type UserSettings

type UserSettings struct {
	DebugInfo bool `json:"debug_info"`
}

func (*UserSettings) Scan

func (s *UserSettings) Scan(value interface{}) error

func (*UserSettings) Value

func (s *UserSettings) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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