users

package
Version: v0.0.0-...-d78814b Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2019 License: GPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

DB is a reference to the parent app's JsonDB object.

View Source
var HashCost = 14

HashCost is the cost value given to bcrypt to hash passwords. TODO: make configurable from main package

Functions

func Create

func Create(u *User) error

Create a new user.

func Normalize

func Normalize(username string) string

Normalize lowercases and safens a username.

func UsernameExists

func UsernameExists(username string) bool

UsernameExists checks if a username is taken.

Types

type ByName

type ByName struct {
	ID int `json:"id"`
}

ByName model maps usernames to their IDs.

type User

type User struct {
	ID       int    `json:"id"`
	Username string `json:"username"`
	Password string `json:"password"`
	Admin    bool   `json:"admin"`
	Name     string `json:"name"`
	Email    string `json:"email"`

	IsAuthenticated bool `json:"-"`
	// contains filtered or unexported fields
}

User holds information about a user account.

func CheckAuth

func CheckAuth(username, password string) (*User, error)

CheckAuth tests a login with a username and password.

func DeletedUser

func DeletedUser() *User

DeletedUser returns a User object to represent a deleted (non-existing) user.

func Load

func Load(id int) (*User, error)

Load a user by their ID number.

func LoadReadonly

func LoadReadonly(id int) (*User, error)

LoadReadonly loads a user for read-only use, so the Password is masked.

func LoadUsername

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

LoadUsername loads a user by username.

func (*User) Save

func (u *User) Save() error

Save the user.

func (*User) SetPassword

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

SetPassword sets a user's password by bcrypt hashing it. After this function, u.Password will contain the bcrypt hash.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL