user

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package user contains handles the state of users.

Index

Constants

This section is empty.

Variables

View Source
var ErrIncorrectLogin error = fmt.Errorf("incorrect username/password")

ErrIncorrectLogin should be returned if a login attempt fails because the credentials are invalid.

Functions

This section is empty.

Types

type Backend added in v1.2.0

type Backend interface {
	// Create adds the username/password pair.
	Create(ctx context.Context, u User) error
	// Get validates the username/password pair and gets the points.
	Read(ctx context.Context, u User) (*User, error)
	// UpdatePassword updates the password for user identified by the username.
	UpdatePassword(ctx context.Context, u User) error
	// UpdatePointsIncrement increments the points for all of the usernames.
	UpdatePointsIncrement(ctx context.Context, usernamePoints map[string]int) error
	// Delete removes the user.
	Delete(ctx context.Context, u User) error
}

Backend contains the operations to manage users

type Dao

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

Dao contains CRUD operations for user-related information.

func NewDao

func NewDao(b Backend) (*Dao, error)

NewDao creates a Dao using the specified backend.

func (Dao) Backend added in v1.2.0

func (d Dao) Backend() Backend

Backend returns the user backend

func (Dao) Create

func (d Dao) Create(ctx context.Context, u User) error

Create adds a user.

func (Dao) Delete

func (d Dao) Delete(ctx context.Context, u User) error

Delete removes a user.

func (Dao) Login

func (d Dao) Login(ctx context.Context, u User) (*User, error)

Login gets ensures the username/password combination is valid and returns all information about the user. The user is returned if the backend is a NoDatabaseBackend.

func (Dao) UpdatePassword

func (d Dao) UpdatePassword(ctx context.Context, u User, newPassword string) error

UpdatePassword sets the password of a user.

func (Dao) UpdatePointsIncrement

func (d Dao) UpdatePointsIncrement(ctx context.Context, usernamePoints map[string]int) error

UpdatePointsIncrement increments the points for multiple users by the amount defined in the map.

type NoDatabaseBackend added in v1.2.0

type NoDatabaseBackend struct{}

func (NoDatabaseBackend) Create added in v1.2.0

func (b NoDatabaseBackend) Create(ctx context.Context, u User) error

Create returns an error.

func (NoDatabaseBackend) Delete added in v1.2.0

func (b NoDatabaseBackend) Delete(ctx context.Context, u User) error

Delete returns an error.

func (NoDatabaseBackend) Read added in v1.2.0

func (b NoDatabaseBackend) Read(ctx context.Context, u User) (*User, error)

Read returns the user.

func (NoDatabaseBackend) UpdatePassword added in v1.2.0

func (b NoDatabaseBackend) UpdatePassword(ctx context.Context, u User) error

UpdatePassword returns an error

func (NoDatabaseBackend) UpdatePointsIncrement added in v1.2.0

func (b NoDatabaseBackend) UpdatePointsIncrement(ctx context.Context, usernamePoints map[string]int) error

UpdatePointsIncrement returns an error.

type User

type User struct {
	Username string
	Password string
	Points   int
}

User contains information for each player.

func (User) Validate added in v1.2.0

func (u User) Validate() error

Validate checks if the username and password are valid.

Directories

Path Synopsis
Package bcrypt contains password hashing and checking logic for stored passwords.
Package bcrypt contains password hashing and checking logic for stored passwords.

Jump to

Keyboard shortcuts

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