auth

package
v0.0.0-...-92255fb Latest Latest
Warning

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

Go to latest
Published: Mar 28, 2017 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	NoUser       = ""
	StandardUser = "standard"
	StaffUser    = "staff"
	AdminUser    = "admin"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

Auth manages access to users. This includes adding and removing users. Only staff can change settings and only the administrator can perform user actions.

func New

func New(config *config.Config) (*Auth, error)

New creates a new authenticator for registered users. A special entry is created for the admin user.

func (*Auth) Authenticate

func (a *Auth) Authenticate(username, password string) (*User, error)

Authenticate attempts to authenticate the specified using their username and password. To make things harder for malicious users, there is no distinguishing between invalid usernames and invalid passwords.

func (*Auth) CreateUser

func (a *Auth) CreateUser(username, userType string) (string, error)

CreateUser creates a new user. Their randomly-generated password is returned if the process completes without error.

func (*Auth) Delete

func (a *Auth) Delete(username string) error

Delete removes the specified user account.

func (*Auth) Get

func (a *Auth) Get(username string) (*User, error)

Get retrieves a specific user.

func (*Auth) ResetPassword

func (a *Auth) ResetPassword(username string) (string, error)

ResetPassword attempts to reset a user's password.

func (*Auth) SetPassword

func (a *Auth) SetPassword(username, password string) error

SetPassword attempts to set a new password for a user.

func (*Auth) Users

func (a *Auth) Users() map[string]*User

Users returns a map of usernames to their account information.

type User

type User struct {
	PasswordHash   []byte    `json:"password_hash"`
	ChangePassword bool      `json:"change_password"`
	Type           string    `json:"type"`
	Created        time.Time `json:"created"`
}

User represents information for a registered user.

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin determines if the user is an admin.

func (*User) IsStaff

func (u *User) IsStaff() bool

IsStaff determines if the user is a staff member.

Jump to

Keyboard shortcuts

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