memory

package
v0.0.3-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package memory provides an implementation of api.UserService that uses memory as a storage.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type UserService

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

UserService stores all the users in memory and implements auth.UserService interface.

func New

func New() *UserService

New returns a new UserService. It initialises the underlying storage which in this case is map.

func (*UserService) Authenticate

func (s *UserService) Authenticate(u api.UserLogin) (api.UserInfo, error)

Authenticate authenticates a user by validating that it exists and hash of the provided password matches. On success returns a JWT token. While this method returns different errors for different failures the end user should only see a generic "invalid credentials" message.

func (*UserService) Create

func (s *UserService) Create(u api.UserRegister) error

Create creates a new user. Returns an error if user with the same username or the same email already exist or if passwords do not match.

func (*UserService) Validate

func (s *UserService) Validate(u api.User, t string) (api.UserInfo, error)

Validate checks if provided token is valid. It returns auth.UserInfo with Username and Token if the token is valid or an empty UserInfo and an error if the token is invalid or if there was another error.

Jump to

Keyboard shortcuts

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