service

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BufferNotifier

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

BufferNotifier uses a byte buffer for notifications.

func NewBufferNotifier

func NewBufferNotifier() *BufferNotifier

NewBufferNotifier creates a new notifier.

func (*BufferNotifier) Notify

func (b *BufferNotifier) Notify(email string, event Event, payload string) error

Notify uses a buffer to store notifications for a user.

type EmailNotifier

type EmailNotifier struct{}

EmailNotifier is an email based notification entity.

func NewEmailNotifier

func NewEmailNotifier() EmailNotifier

NewEmailNotifier creates a new email notifier.

func (EmailNotifier) Notify

func (e EmailNotifier) Notify(email string, event Event, payload string) error

Notify attempts to send out an email using mailgun contaning the new password. Does not need to be a pointer receiver because it isn't storing anything.

type Event

type Event string

Event represents an event that can happen which needs the user's attention via prefered notification medium.

var (
	// PasswordReset is an event that happens when the user's password is reset.
	PasswordReset Event = "Password Reset"
	// GenerateConfirmCode is an event before password reset which sends a confirm code to the user's email address.
	GenerateConfirmCode Event = "Confirm Code"
	// Welcome template for new sign-ups.
	Welcome Event = "Welcome"
)

type Notifier

type Notifier interface {
	Notify(email string, event Event, payload string) error
}

Notifier notifies the user of some event.

type Payload

type Payload string

Payload is data which the notifier carries.

type Stapler

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

Stapler defines a stapler which stores the staples in Postgres DB.

func NewStapler

func NewStapler(storer storage.StapleStorer) Stapler

NewStapler creates a new Postgres based Stapler which will have a connection to a DB.

func (Stapler) Archive

func (p Stapler) Archive(user *models.User, id int) error

Archive will archive a staple which isn't removed but rather not shown in the queue. Archived Staples can be retrieved and vewied in any order.

func (Stapler) Create

func (p Stapler) Create(staple models.Staple, user *models.User) error

Create creates a new Staple for the given user. noinspection GoErrorStringFormat

func (Stapler) Delete

func (p Stapler) Delete(user *models.User, id int) (err error)

Delete deletes a given staple for a user.

func (Stapler) Get

func (p Stapler) Get(user *models.User, id int) (*models.Staple, error)

Get retrieves a Staple for a given user with ID.

func (Stapler) GetNext

func (p Stapler) GetNext(user *models.User) (*models.Staple, error)

GetNext will retrieve the oldest entry from the list that is not archived.

func (Stapler) List

func (p Stapler) List(user *models.User) ([]models.Staple, error)

List lists all staples for a given user.

func (Stapler) ShowArchive

func (p Stapler) ShowArchive(user *models.User) ([]models.Staple, error)

ShowArchive returns the list of archived staples for a given user. This must support pagination. For now return everything and the frontend will paginate.

type Staplerer

type Staplerer interface {
	Create(staple models.Staple, user *models.User) (err error)
	Delete(user *models.User, id int) (err error)
	Get(user *models.User, id int) (staple *models.Staple, err error)
	GetNext(user *models.User) (staple *models.Staple, err error)
	List(user *models.User) (staples []models.Staple, err error)
	Archive(user *models.User, id int) (err error)
	ShowArchive(use *models.User) ([]models.Staple, error)
}

Staplerer describes a stapler service which takes care of managing the user's staples.

type UserHandler

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

UserHandler defines a storage using user handler.

func NewUserHandler

func NewUserHandler(ctx context.Context, store storage.UserStorer, notifier Notifier) UserHandler

NewUserHandler creates a new user handler.

func (UserHandler) ChangePassword

func (u UserHandler) ChangePassword(user models.User, newPassword string) error

ChangePassword changes the user's password to a new given string.

func (UserHandler) Delete

func (u UserHandler) Delete(user models.User) error

Delete removes a user.

func (UserHandler) GetMaximumStaples

func (u UserHandler) GetMaximumStaples(user models.User) (staples int, err error)

GetMaximumStaples returns the maximum allowed configured staples for a user.

func (UserHandler) IsRegistered

func (u UserHandler) IsRegistered(user models.User) (ok bool, err error)

IsRegistered checks if a user exists in the system.

func (UserHandler) PasswordMatch

func (u UserHandler) PasswordMatch(user models.User) (ok bool, err error)

PasswordMatch checks if a stored password matches that of a given one.

func (UserHandler) Register

func (u UserHandler) Register(user models.User) error

Register registers a user.

func (UserHandler) ResetPassword

func (u UserHandler) ResetPassword(user models.User) error

ResetPassword generates a new password for a user and send it via email. This happens after the confirmation was successfull.

func (UserHandler) SendConfirmCode

func (u UserHandler) SendConfirmCode(user models.User) error

SendConfirmCode sends a confirm code which has to be verified.

func (UserHandler) SetMaximumStaples

func (u UserHandler) SetMaximumStaples(user models.User, maxStaples int) error

SetMaximumStaples sets the user's maximum number of allowed staples.

func (UserHandler) VerifyConfirmCode

func (u UserHandler) VerifyConfirmCode(user models.User) (ok bool, err error)

VerifyConfirmCode will match the confirm code with a stored code for an email address. If the match is successful the code is removed and the password is reset.

type UserHandlerer

type UserHandlerer interface {
	Register(user models.User) error
	Delete(user models.User) error
	ResetPassword(user models.User) error
	IsRegistered(user models.User) (ok bool, err error)
	PasswordMatch(user models.User) (ok bool, err error)
	SendConfirmCode(user models.User) error
	VerifyConfirmCode(user models.User) (bool, error)
	SetMaximumStaples(user models.User, maxStaples int) error
	GetMaximumStaples(user models.User) (int, error)
	ChangePassword(user models.User, newPassword string) error
}

UserHandlerer defines a service which can manage users.

Jump to

Keyboard shortcuts

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