users

package
v0.0.0-...-a5a6d41 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2018 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package users handles user authentication, user items etc.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrEmail is returned when the email address provided is wrong
	ErrEmail = errors.New("Invalid or no email provided")
	// ErrCreate is returned if there's an error creating new user
	ErrCreate = errors.New("Sorry, an error occurred while creating new user")
	// ErrInvPwd is returned if the password is invalid
	ErrInvPwd = errors.New("Sorry, invalid or no password provided")
	// ErrUsrNotExists is returned when trying to login with an non-registered email
	ErrUsrNotExists = errors.New("Sorry, there's no user registered with that email")
	// ErrUsrExists is returned when trying to create a user with the same email
	ErrUsrExists = errors.New("Sorry, user with that email already exists")
	// ErrNotAuthenticated is returned when the user is not authenticated and trying to perform
	// an action which requires authentication
	ErrNotAuthenticated = errors.New("Sorry, the user is not authenticated")
	// ErrUnauthorized is returned whenever the user tries to perform an unauthorized action
	ErrUnauthorized = errors.New("Sorry, you're not authorized to perform this action")
	// ErrMalformedCipher is returned when the cipher text is invalid and cannot be used
	ErrMalformedCipher = errors.New("malformed ciphertext")
)

Functions

This section is empty.

Types

type Service

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

Service holds all the dependencies of items

func NewService

func NewService(ss storage.Service, cs cache.Service, l logger.Service, i items.Service) Service

NewService returns a new instance of Service with all the dependencies initialized

func (*Service) AuthUser

func (s *Service) AuthUser(authToken string, tokenSalt string) (*User, error)

AuthUser returns an authenticated user instance from the auth token

func (*Service) Authenticate

func (s *Service) Authenticate(email, password, tokenSalt string) (*User, error)

Authenticate authenticates a user and returns the user instance along with the auth token

func (*Service) Create

func (s *Service) Create(user User) (*User, error)

Create creates a new user

func (*Service) CreateItem

func (s *Service) CreateItem(user *User, data map[string]string) (*items.Item, error)

CreateItem adds a new item owned by the user

func (*Service) Delete

func (s *Service) Delete(user *User) (*User, error)

Delete deletes the provided User

func (*Service) DeleteItem

func (s *Service) DeleteItem(user *User, itemID string) (*items.Item, error)

DeleteItem removes an item owned by the user

func (*Service) Item

func (s *Service) Item(user *User, itemID string) (*items.Item, error)

Item returns a decrypted item

func (*Service) Items

func (s *Service) Items(user *User, start, limit int) ([]items.Item, error)

Items returns list of items the user owns

func (*Service) Read

func (s *Service) Read(email string) (*User, error)

Read reads a user given the email

func (*Service) Update

func (s *Service) Update(user *User, data map[string]string) (*User, error)

Update reads a user given the email

func (*Service) UpdateItem

func (s *Service) UpdateItem(user *User, itemID string, data map[string]string) (*items.Item, error)

UpdateItem updates an item owned by the user

type User

type User struct {
	ID                string     `json:"id,omitempty" bson:"id,omitempty"`
	Name              string     `json:"name,omitempty" bson:"name,omitempty"`
	Email             string     `json:"email,omitempty" bson:"email,omitempty"`
	Password          []byte     `json:"-" bson:"password,omitempty"`
	Salt              string     `json:"-" bson:"salt,omitempty"`
	AuthToken         string     `bson:"-" json:"authToken,omitempty"`
	EncryptedPassword []byte     `bson:"-" json:"-"`
	CreatedAt         *time.Time `json:"createdAt,omitempty" bson:"createdAt,omitempty"`
	ModifiedAt        *time.Time `json:"modifiedAt,omitempty" bson:"modifiedAt,omitempty"`
}

User struct holds all the user details

func New

func New(data map[string]string) (*User, error)

New returns a user instance based on the provided data

Jump to

Keyboard shortcuts

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