user

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2017 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	Unauthorized                 = NewError(401, "unauthorized")
	UserNotFound                 = NewError(1000, "user not found")
	SaltNotFound                 = NewError(1001, "salt not found")
	PasswordUsed                 = NewError(1002, "password already used")
	UsernameMissing              = NewError(1100, "username missing")
	UsernameInvalid              = NewError(1101, "username invalid")
	UsernameExists               = NewError(1102, "username exists")
	EmailMissing                 = NewError(1200, "email missing")
	EmailInvalid                 = NewError(1201, "email invalid")
	EmailExists                  = NewError(1202, "email exists")
	EmailChangeEmailNotAvaliable = NewError(1300, "email not available for change")
	EmailValidateTokenNotFound   = NewError(1301, "email validation token not found")
	EmailValidateTokenInvalid    = NewError(1302, "email validation token invalid")
	EmailValidateTokenExpired    = NewError(1303, "email validation token expired")
	PasswordResetTokenNotFound   = NewError(1400, "password reset token not found")
	PasswordResetTokenExpired    = NewError(1401, "password reset token expired")
)

Errors that are related to the User Services.

View Source
var (
	// ErrorRegistry is a map of error codes to errors.
	// It is usually used in gopherpit.com/gopherpit/pkg/client.Client.
	ErrorRegistry = apiClient.NewMapErrorRegistry(nil)
)

Functions

This section is empty.

Types

type Authenticator

type Authenticator interface {
	// Authenticate validates a password of an existing User.
	Authenticate(ref, password string) (u *User, err error)
}

Authenticator authenticates a User by a reference and password.

type EmailService

type EmailService interface {
	// RequestEmailChange starts a process of changing an email by
	// returning a token that must be used in ChangeEmail to authorize
	// email change.
	RequestEmailChange(ref, email string, validationDeadline time.Time) (token string, err error)
	// ChangeEmail changes an email of an existing User only if
	// provided token is valid.
	ChangeEmail(ref, token string) (*User, error)
	// EmailChangeToken retrieves a token to change an email if it exists.
	EmailChangeToken(ref, email string) (token string, err error)
}

EmailService handles e-mail changes.

type Error

type Error struct {
	// Message is a text that describes an error.
	Message string `json:"message"`
	// Code is a number that identifies error.
	// It allows error identification when serialization is involved.
	Code int `json:"code"`
}

Error is a structure that holds error message and code.

func NewError

func NewError(code int, message string) (err *Error)

NewError creates an instance of Error and adds it to ErrorRegistry. If error code already exists in ErrorRegistry, it panics.

func (*Error) Error

func (e *Error) Error() string

Error returns error message.

type ManagementService

type ManagementService interface {
	// User retrieves a User instance.
	User(ref string) (*User, error)
	// UserByID retrieves a User instance only by it's ID.
	UserByID(id string) (*User, error)
	// UserByID retrieves a User instance only by it's Email.
	UserByEmail(email string) (*User, error)
	// UserByID retrieves a User instance only by it's Username.
	UserByUsername(username string) (*User, error)
	// Create user creates a new user interface.
	CreateUser(o *Options) (*User, error)
	// UpdateUser changes data of an existing User.
	UpdateUser(ref string, o *Options) (*User, error)
	// SetPassword changes a password of an existing User.
	SetPassword(ref string, password string) error
	// DeleteUser deletes an existing User.
	DeleteUser(ref string) (*User, error)

	// UsersByID retrieves a paginated list of User instances ordered by
	// ID values.
	UsersByID(startID string, limit int) (*UsersPage, error)
	// UsersByEmail retrieves a paginated list of User instances ordered by
	// Email values.
	UsersByEmail(startEmail string, limit int) (*UsersPage, error)
	// UsersByUsername retrieves a paginated list of User instances ordered by
	// Username values.
	UsersByUsername(startUsername string, limit int) (*UsersPage, error)
}

ManagementService defines most basic functionality for user management.

type Options

type Options struct {
	Email                 *string `json:"email,omitempty"`
	Username              *string `json:"username,omitempty"`
	Name                  *string `json:"name,omitempty"`
	Admin                 *bool   `json:"admin,omitempty"`
	NotificationsDisabled *bool   `json:"notifications-disabled,omitempty"`
	EmailUnvalidated      *bool   `json:"email-unvalidated,omitempty"`
	Disabled              *bool   `json:"disabled,omitempty"`
}

Options is a structure with parameters as pointers to set user data. If a parameter is nil, the corresponding User parameter will not be changed.

type PasswordResetService

type PasswordResetService interface {
	// RequestPasswordReset starts a process of reseting a password by
	// providing a token that must be used in ResetPassword to authorize
	// password reset.
	RequestPasswordReset(ref string) (token string, err error)
	// ResetPassword changes a password of an existing User only if
	// provided token is valid.
	ResetPassword(token, password string) error
}

PasswordResetService handles password changes.

type RegisterService

type RegisterService interface {
	// RegisterUser is a method for adding new users.
	RegisterUser(o *Options, password string, emailValidationDeadline time.Time) (u *User, emailValidationToken string, err error)
}

RegisterService defines user registration interface.

type Service

Service defines functions that User provider must have. Argument ref in some functions can be a string that is uniquely defined for a user: ID, Username or Email.

type User

type User struct {
	ID                    string `json:"id"`
	Email                 string `json:"email"`
	Username              string `json:"username,omitempty"`
	Name                  string `json:"name,omitempty"`
	Admin                 bool   `json:"admin,omitempty"`
	NotificationsDisabled bool   `json:"notifications-disabled,omitempty"`
	EmailUnvalidated      bool   `json:"email-unvalidated,omitempty"`
	Disabled              bool   `json:"disabled,omitempty"`
}

User holds user account related data.

func (User) String

func (u User) String() string

type UsersPage

type UsersPage struct {
	Users []User `json:"users"`
	// Previous is an reference that
	// can be used to retrieve previous page.
	Previous string `json:"previous"`
	// Previous is an reference that
	// can be used to retrieve next page.
	Next string `json:"next"`
	// Count is a number of User instances in this UserPage.
	Count int `json:"count"`
}

UsersPage is a paginated list of User instances.

Directories

Path Synopsis
Package boltUser provides a Service that is using local BoltDB database to store User data.
Package boltUser provides a Service that is using local BoltDB database to store User data.
Package httpUser provides a Service that is a HTTP client to an external user service that can respond to HTTP requests defined here.
Package httpUser provides a Service that is a HTTP client to an external user service that can respond to HTTP requests defined here.
Package ldapUser provides a Service that uses LDAP for user authentication.
Package ldapUser provides a Service that uses LDAP for user authentication.

Jump to

Keyboard shortcuts

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