Documentation
¶
Overview ¶
Package users implements operations for user data manipulation.
Index ¶
- Variables
- func Add(ctx context.Context, args AddUserRequest) (string, error)
- func Equals(a, b models.User) bool
- func Filter(users []models.User, filters ...FilterFunc) []models.User
- func Online(u models.User) bool
- func Private(u models.User) bool
- func PublicSlice(u []models.User) []models.UserPublicData
- func StrictEquals(a, b models.User) bool
- func Update(old models.User, c *Changes) models.User
- func VerifyNickname(n string) bool
- func VerifyPassword(p string) bool
- func VerifyRegisterData(nickname, password string) error
- type AddUserRequest
- type AuthenticationDependencies
- type AuthenticationRequest
- type AuthenticationResponse
- type Changes
- type FilterFunc
Constants ¶
This section is empty.
Variables ¶
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 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 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 ¶
StrictEquals returns true if both users have same values assigned to every field.
func VerifyNickname ¶ added in v0.3.3
VerifyNickname verifies if given nickname string is proper nickname for long-season application.
func VerifyPassword ¶ added in v0.3.3
VerifyPassword verifies if given password string is proper password for long-season application.
func VerifyRegisterData ¶ added in v0.3.3
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 FilterFunc ¶ added in v0.3.0
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.