userctrl

package
v0.0.0-...-bd94320 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Settings

type Settings struct {
	UserRepo  UserRepository
	Resolver  *jwtresolver.JWTResolver
	Validator *validator.Validator
}

Settings used to create UserController. Settings must be provided to New function. All fields are required and cant be nil.

type UserController

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

UserController used to register and login users. Must be created with New function.

func New

func New(settings Settings) *UserController

New creates new UserController. Returns pointer to UserController. Accepts Settings as argument.

func (*UserController) Login

func (c *UserController) Login(
	ctx context.Context,
	credentials models.Credentials,
) (string, error)

Login returns JWT token with user ID or error if login failed. Must be called with valid credentials with non-empty login and password.

func (*UserController) Register

func (c *UserController) Register(
	ctx context.Context,
	credentials models.Credentials,
) (string, error)

Register registers new user and returns JWT token with user ID. Returns error if registration failed. Must be called with valid credentials with non-empty login, password and token.

type UserRepository

type UserRepository interface {
	// AddUser add user to repository.
	AddUser(ctx context.Context, login, passHash string) (uuid.UUID, error)

	// GetUserByLogin get user from repository.
	GetUserByLogin(ctx context.Context, login string) (models.User, error)
}

UserRepository used to get user by login and add user.

Jump to

Keyboard shortcuts

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