user

package
v0.0.0-...-29f5810 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package user provides an API for users and access management.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotValid      = errors.New("invalid user")
	ErrWrongPassword = errors.New("wrong password")
	ErrPasswordMatch = errors.New("passwords do not match")
	ErrNotFound      = errors.New("user not found")
)

Roles collects all roles required for a project.

Functions

func CheckMAC

func CheckMAC(msg, msgMAC, key []byte) bool

CheckMAC checks the message with a msgMAC using the provided key. Use it for a password check.

func MakeMAC

func MakeMAC(msg, key []byte) ([]byte, error)

MakeMAC creates a HMAC from a message and a key.

func RandStringRunes

func RandStringRunes(n int) string

RandStringRunes returns a random string with the length of n.

func SetLoginCookie

func SetLoginCookie(w http.ResponseWriter, u *User, c *securecookie.SecureCookie, t time.Duration) error

SetLoginCookie sets a secure cookie.

func SetLogoutCookie

func SetLogoutCookie(w http.ResponseWriter)

SetLogoutCookie partially implements user.Authenticator interface.

func Validate

func Validate(u *User) bool

Validate checks if all compulsory fields are present.

func Verify

func Verify(password string, passwordHash, key []byte) bool

Verify implements user.Authenticator interface.

Types

type Role

type Role int

Role represents a user's role. It's a mean for access control.

const (

	// Administrator is able to modify other users.
	Administrator Role

	// Author can enter tne /admin endpoint.
	Author

	// Visitor is any other user.
	Visitor

	// Expert is an expert in the Infocenter.
	Expert
)

func (Role) String

func (i Role) String() string

type User

type User struct {
	ID           bson.ObjectId `bson:"_id"`
	FirstName    string
	LastName     string
	Created      time.Time
	Active       bool
	Email        mail.Address
	PasswordHash []byte
	Roles        []Role
}

User represents a user of a system.

func New

func New(password, email, firstName, lastName string, roles []Role, key []byte) (u *User, err error)

New returns a new user with all compulsory attributes.

Jump to

Keyboard shortcuts

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