Documentation ¶
Overview ¶
Package users provides an example of a core business API. Right now these calls are just wrapping the data/data layer. But at some point you will want auditing or something that isn't specific to the data/store layer.
Index ¶
- Variables
- type ChangePassword
- type Core
- func (c Core) Authenticate(ctx context.Context, email, password string) (auth.Claims, error)
- func (c Core) ChangePassword(ctx context.Context, userID string, cp ChangePassword, now time.Time) error
- func (c Core) Create(ctx context.Context, nu NewUser, now time.Time, inviteDate ...string) (User, error)
- func (c Core) QueryByEmail(ctx context.Context, email string) (User, error)
- func (c Core) QueryByID(ctx context.Context, userID string) (User, error)
- func (c Core) Update(ctx context.Context, userID string, uu UpdateUser, now time.Time) error
- func (c Core) UpdateImage(ctx context.Context, userID string, ui UpdateImage, now time.Time) error
- type NewUser
- type UpdateImage
- type UpdateUser
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("user not found") ErrInvalidID = errors.New("ID is not in its proper form") ErrInvalidEmail = errors.New("email is not valid") ErrUniqueEmail = errors.New("email is not unique") ErrAuthenticationFailure = errors.New("authentication failed") ErrInvalidPassword = errors.New("password is not valid") )
Set of error variables for CRUD operations.
Functions ¶
This section is empty.
Types ¶
type ChangePassword ¶
type ChangePassword struct { OldPassword string `json:"old_password" validate:"required,min=6,max=64"` Password *string `json:"Password" validate:"required,min=6,max=64"` }
ChangePassword defines what information may be provided to change an existing user's password.
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core manages the set of APIs for user access.
func NewCore ¶
func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB) Core
NewCore constructs a core for user api access.
func (Core) Authenticate ¶
Authenticate finds a user by their email and verifies their password. On success it returns a Claims User representing this user. The claims can be used to generate a token for future authentication.
func (Core) ChangePassword ¶
func (c Core) ChangePassword(ctx context.Context, userID string, cp ChangePassword, now time.Time) error
ChangePassword replaces a user document in the database.
func (Core) Create ¶
func (c Core) Create(ctx context.Context, nu NewUser, now time.Time, inviteDate ...string) (User, error)
Create inserts a new user into the database.
func (Core) QueryByEmail ¶
QueryByEmail gets the specified user from the database by email.
func (Core) UpdateImage ¶
UpdateImage replaces a user document in the database.
type NewUser ¶
type NewUser struct { Email string `json:"email" validate:"required,email"` Password string `json:"password" validate:"required,min=6,max=64"` }
NewUser contains information needed to create a new user.
type UpdateImage ¶
type UpdateImage struct {
ImageName string `json:"image_name" validate:"required,omitempty"`
}
UpdateImage defines what information may be provided to update an existing user's image.
type UpdateUser ¶
type UpdateUser struct { DefaultWid *string `json:"default_wid"` Email *string `json:"email" validate:"omitempty,email"` FullName *string `json:"full_name"` TimeOfDayFormat *string `json:"time_of_day_format" validate:"omitempty,eq=H:mm|eq=h:mm"` DateFormat *string `json:"date_format" validate:"omitempty,eq=YYYY-MM-DD|eq=DD.MM.YYYY|eq=DD-MM-YYYY|eq=MM/DD/YYYY|eq=DD/MM/YYYY|eq=MM-DD-YYYY"` BeginningOfWeek *int `json:"beginning_of_week" validate:"omitempty,min=0|max=6"` Language *string `json:"language"` DateCreated *time.Time `json:"date_created"` DateUpdated *time.Time `json:"date_updated"` TimeZone *string `json:"timezone"` Invitation []string `json:"invitation"` DurationFormat *string `json:"duration_format"` }
UpdateUser defines what information may be provided to modify an existing user. All fields are optional so user can send just the fields they want changed. It uses pointer fields ,so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types ,but we make exceptions around marshalling/unmarshalling.
type User ¶
type User struct { ID string `json:"id"` DefaultWid string `json:"default_wid"` Email string `json:"email"` PasswordHash []byte `json:"password_hash"` FullName string `json:"full_name"` TimeOfDayFormat string `json:"time_of_day_format"` DateFormat string `json:"date_format"` BeginningOfWeek int `json:"beginning_of_week"` Language string `json:"language"` ImageURL string `json:"image_url"` DateCreated time.Time `json:"date_created"` DateUpdated time.Time `json:"date_updated"` TimeZone string `json:"timezone"` Invitation []string `json:"invitation"` DurationFormat string `json:"duration_format"` }
User represents an individual user.