users

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Overview

Package users implements operations for user data manipulation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidNickname error is used for various verifies to
	// signal that user verification failed because of
	// invalid username. Raw message of error is safe to output
	// to client.
	ErrInvalidNickname = errors.New(invalidNicknameMsg)

	// ErrInvaliPassword error is used for various verifies to
	// signal that user verification failed because of
	// invalid password. Raw message of error is safe to output
	// to client.
	ErrInvaliPassword = errors.New(invalidPasswordMsg)
)

Functions

func Add added in v0.5.0

func Add(ctx context.Context, args AddUserRequest) (string, error)

Add adds new User to given storage with default options. Returns new users ID if succeds.

func Equals

func Equals(a, b models.User) bool

Equals returns true if both users have same nickname, password and mac address.

func Filter added in v0.3.0

func Filter(users []models.User, filters ...FilterFunc) []models.User

Filter returns slice of users that passed all given FilterFunc tests. If no filters given, returns exactly same slice of users that has been passed to function.

func Online added in v0.3.0

func Online(u models.User) bool

Online returns true if given user is currently online.

func Private added in v0.3.0

func Private(u models.User) bool

Private returns true if given user has private flag set to true.

func PublicSlice

func PublicSlice(u []models.User) []models.UserPublicData

PublicSlice returns new slice with only public user data, created from given slice containing full user data.

func StrictEquals

func StrictEquals(a, b models.User) bool

StrictEquals returns true if both users have same values assigned to every field.

func Update

func Update(old models.User, c *Changes) models.User

Update applies given changes to given user model and returns new user model.

func VerifyNickname added in v0.3.3

func VerifyNickname(n string) bool

VerifyNickname verifies if given nickname string is proper nickname for long-season application.

func VerifyPassword added in v0.3.3

func VerifyPassword(p string) bool

VerifyPassword verifies if given password string is proper password for long-season application.

func VerifyRegisterData added in v0.3.3

func VerifyRegisterData(nickname, password string) error

VerifyRegisterData verifies if given data required for user registration is valid. Returned error messages are safe to output to client.

Types

type AddUserRequest added in v0.5.0

type AddUserRequest struct {
	// Nickname represents name that will be exposed to public,
	// to inform people who is in the hackerspace.
	Nickname string

	// Raw password.
	Password []byte

	// Storage for users.
	Storage storage.Users
}

AddUserRequest contains arguments and dependencies for adding new User entry to storage.

type AuthenticationDependencies added in v0.4.0

type AuthenticationDependencies struct {
	// Request holds input data.
	Request AuthenticationRequest

	// Storage operates on user data in database.
	Storage storage.Users

	// ErrorFactory is optional. If you want
	// to have debug errors, you can pass
	// error Factory created from http request.
	ErrorFactory *happier.Factory
}

AuthenticationDependencies are dependencies for authenticating user with password.

type AuthenticationRequest added in v0.4.0

type AuthenticationRequest struct {
	// UserID is used to find user.
	UserID string

	// Nickname can be also used to find user as
	// alternative to UserID.
	Nickname string

	// Password is used to verify user with
	// requested nickname.
	Password []byte
}

AuthenticationRequest holds input data for AuthenticateWithPassword function.

type AuthenticationResponse added in v0.5.0

type AuthenticationResponse struct {
	// UserID is used to find user.
	UserID string

	// Nickname can be also used to find user as
	// alternative to UserID.
	Nickname string
}

AuthenticationResponse holds data of authenticated user.

func AuthenticateWithPassword added in v0.4.0

func AuthenticateWithPassword(ctx context.Context, deps AuthenticationDependencies) (*AuthenticationResponse, error)

AuthenticateWithPassword takes aut dependencies with authenticate request and process user data to verify whether given passwords matches or not. It returns user data for convince if authentication passes and nil pointer with error if it doesn't.

type Changes

type Changes struct {
	Nickname string
	Password []byte
	Online   *bool
}

Changes represents possible changes that can be applied to models.User

type FilterFunc added in v0.3.0

type FilterFunc func(models.User) bool

FilterFunc accepts User model and returns true or false.

func DefaultFilters added in v0.3.0

func DefaultFilters() []FilterFunc

DefaultFilters returns slice with convenient collection of default filters that can be used for outputting user data.

For example: default filters contains Not(Private) filter for hiding private users.

func Not added in v0.3.0

func Not(f FilterFunc) FilterFunc

Not returns opposite of given FilterFunc result.

Jump to

Keyboard shortcuts

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