user

package
v0.0.0-...-8ba40cc Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type LoginRequest

type LoginRequest struct {
	User LoginUser `json:"user"`
}

LoginRequest describes request JSON for login handler

func (*LoginRequest) Validate

func (r *LoginRequest) Validate() error

type LoginUser

type LoginUser struct {
	Email    string `json:"email"`
	Password string `json:"password"` // NOTE: Plaintext password from user
}

type RegisterRequest

type RegisterRequest struct {
	User RegisterUser `json:"user"`
}

func (*RegisterRequest) Validate

func (r *RegisterRequest) Validate() error

type RegisterUser

type RegisterUser struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"` // NOTE: Plaintext password from user
}

type Response

type Response struct {
	User app.User `json:"user"`
}

Response represent a json structure used in user serice responses.

type Server

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

func NewHTTP

func NewHTTP(store Store, secret []byte) (*Server, error)

func (*Server) HandleUserGet

func (s *Server) HandleUserGet(w http.ResponseWriter, r *http.Request) error

HandleUserGet gets the currently logged-in user. Requires authentication.

func (*Server) HandleUserLogin

func (s *Server) HandleUserLogin(w http.ResponseWriter, r *http.Request) error

func (*Server) HandleUserRegister

func (s *Server) HandleUserRegister(w http.ResponseWriter, r *http.Request) error

func (*Server) HandleUserUpdate

func (s *Server) HandleUserUpdate(w http.ResponseWriter, r *http.Request) error

HandleUserUpdate changes currently logged-in user. Requires authentication.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.handler interface and uses router ServeHTTP method

type Service

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

Service provides a service for interacting with user accounts

func NewService

func NewService(store Store) *Service

NewService creates new instance of the service with provided store

func (*Service) Get

func (s *Service) Get(email string) (*app.User, error)

Get returns user by email

func (*Service) Login

func (s *Service) Login(req *LoginRequest) (*app.User, error)

Login checks the user request and logins the user

func (*Service) Register

func (s *Service) Register(req *RegisterRequest) (*app.User, error)

Register creates new user in the service

func (*Service) Update

func (s *Service) Update(id int, req *UpdateRequest) (*app.User, error)

Update modifies user found by id with the new data passed in user. It returns updated user.

type Store

type Store interface {
	GetUser(email string) (*app.User, error)
	GetUserById(id int) (*app.User, error)
	AddUser(user *app.User) error
	UpdateUser(user *app.User) error
}

type UpdateRequest

type UpdateRequest struct {
	User UpdateUser `json:"user"`
}

func (*UpdateRequest) Validate

func (r *UpdateRequest) Validate() error

type UpdateUser

type UpdateUser struct {
	Name     string `json:"username,omitempty"`
	Email    string `json:"email,omitempty"`
	Password string `json:"password,omitempty"` // NOTE: Plaintext password from user
	Bio      string `json:"bio,omitempty"`
	Image    string `json:"image,omitempty"`
}

Jump to

Keyboard shortcuts

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