user

package
v0.0.0-...-0ba6107 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2017 License: MIT Imports: 3 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrNotFound if the user does not exist in a store.
	ErrNotFound = wwm.Error{"User does not exist", http.StatusNotFound}
)
View Source
var (
	// Hans is a pseudo user with admin role
	Hans = User{
		Login: Login{
			Mail:     "hans@gmail.com",
			Password: "hansistsogeil",
		},
		Roles: []string{"admin"},
		PayPal: PayPal{
			MeLink: "http://www.paypal.me/hans",
		},
	}
)
View Source
var (
	// RoleAdmin the super role for a user
	RoleAdmin = "admin"
)

Functions

This section is empty.

Types

type Login

type Login struct {
	Mail     string `json:"mail"`
	Password string `json:"password"`
}

Login describes the information necessary for a user.

func (Login) ToString

func (l Login) ToString() string

ToString creates a console representation, that does hide the password.

type PayPal

type PayPal struct {
	MeLink string `json:"meLink"`
}

PayPal contains the information needed for a PayPal payment.

type PublicUser

type PublicUser struct {
	Mail         string   `json:"mail"`
	PayPalMeLink string   `json:"payPalMeLink"`
	Roles        []string `json:"roles"`
}

PublicUser contains all information of a user that are not private.

type ReadStore

type ReadStore interface {
	FindByMail(string) (User, error)
	FindAll() ([]User, error)
	FindByRegistrationID(registrationID string) (User, error)
}

ReadStore can be used to do query operations for a User. The Mail of Login is used as id.

type Store

type Store interface {
	ReadStore
	WriteStore
}

Store can read and write for a user.

type User

type User struct {
	Login          `json:"login"`
	PayPal         PayPal         `json:"payPal"`
	RegistrationID string         `json:"registrationID"`
	Roles          []string       `json:"roles"`
	DefaultOrders  map[string]int `json:"defaultOrders"`
	MailEnabled    bool           `json:"mailEnabled"`
}

User describes the aggregate of a user.

func (User) HasMail

func (u User) HasMail(mails ...string) bool

HasMail finds out if the User has at least one of the given mails. If the user is an admin he always wins.

func (User) HasRole

func (u User) HasRole(roles ...string) bool

HasRole finds out if the user has at a least one of the given roles. If the user is an admin he always wins.

func (User) IsAdmin

func (u User) IsAdmin() bool

IsAdmin checks if the user is an admin

func (User) IsRegistered

func (user User) IsRegistered() bool

IsRegistered returns if the user is fully registered.

func (User) PublicUser

func (u User) PublicUser() (p PublicUser)

PublicUser representation of a user.

type WriteStore

type WriteStore interface {
	Save(User) error
	RemoveByMail(string) error
}

WriteStore saves or removes a user.

Directories

Path Synopsis
adapter

Jump to

Keyboard shortcuts

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