Documentation
¶
Overview ¶
Package httpUser provides a Service that is a HTTP client to an external user service that can respond to HTTP requests defined here.
Index ¶
- type AuthenticateRequest
- type AuthenticateResponse
- type ChangeEmailRequest
- type EmailChangeTokenResponse
- type RegisterUserRequest
- type RegisterUserResponse
- type RequestEmailChangeRequest
- type RequestEmailChangeResponse
- type RequestPasswordResetResponse
- type ResetPasswordRequest
- type Service
- func (s Service) Authenticate(ref, password string) (u *user.User, err error)
- func (s Service) ChangeEmail(ref, token string) (u *user.User, err error)
- func (s Service) CreateUser(o *user.Options) (u *user.User, err error)
- func (s Service) DeleteUser(ref string) (u *user.User, err error)
- func (s Service) EmailChangeToken(ref, email string) (token string, err error)
- func (s Service) RegisterUser(o *user.Options, password string, emailValidationDeadline time.Time) (u *user.User, emailValidationToken string, err error)
- func (s Service) RequestEmailChange(ref, email string, validationDeadline time.Time) (token string, err error)
- func (s Service) RequestPasswordReset(ref string) (token string, err error)
- func (s Service) ResetPassword(token, password string) (err error)
- func (s Service) SetPassword(ref string, password string) (err error)
- func (s Service) UpdateUser(ref string, o *user.Options) (u *user.User, err error)
- func (s Service) User(ref string) (u *user.User, err error)
- func (s Service) UserByEmail(email string) (u *user.User, err error)
- func (s Service) UserByID(id string) (u *user.User, err error)
- func (s Service) UserByUsername(username string) (u *user.User, err error)
- func (s Service) UsersByEmail(startEmail string, limit int) (page *user.UsersPage, err error)
- func (s Service) UsersByID(startID string, limit int) (page *user.UsersPage, err error)
- func (s Service) UsersByUsername(startUsername string, limit int) (page *user.UsersPage, err error)
- type SetPasswordRequest
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthenticateRequest ¶
type AuthenticateRequest struct {
Password string `json:"password"`
}
AuthenticateRequest is a structure that is passed as JSON-encoded body to Authenticate HTTP request.
type AuthenticateResponse ¶
AuthenticateResponse is expected structure of JSON-encoded response body for Authenticate HTTP request.
type ChangeEmailRequest ¶
type ChangeEmailRequest struct {
Token string `json:"token"`
}
ChangeEmailRequest is a structure that is passed as JSON-encoded body to ChangeEmail HTTP request.
type EmailChangeTokenResponse ¶
type EmailChangeTokenResponse struct {
Token string `json:"token"`
}
EmailChangeTokenResponse is expected structure of JSON-encoded response body for EmailChangeToken HTTP request.
type RegisterUserRequest ¶
type RegisterUserRequest struct {
Options *user.Options `json:"options"`
Password string `json:"password"`
EmailValidationDeadline time.Time `json:"email-validation-deadline"`
}
RegisterUserRequest is a structure that is passed as JSON-encoded body to RegisterUser HTTP request.
type RegisterUserResponse ¶
type RegisterUserResponse struct {
User *user.User `json:"user"`
EmailValidationToken string `json:"email-validation-token"`
}
RegisterUserResponse is expected structure of JSON-encoded response body for RegisterUser HTTP request.
type RequestEmailChangeRequest ¶
type RequestEmailChangeRequest struct {
Email string `json:"email"`
ValidationDeadline time.Time `json:"validation-deadline"`
}
RequestEmailChangeRequest is a structure that is passed as JSON-encoded body to RequestEmailChange HTTP request.
type RequestEmailChangeResponse ¶
type RequestEmailChangeResponse struct {
Token string `json:"token"`
}
RequestEmailChangeResponse is expected structure of JSON-encoded response body for RequestEmailChange HTTP request.
type RequestPasswordResetResponse ¶
type RequestPasswordResetResponse struct {
Token string `json:"token"`
}
RequestPasswordResetResponse is expected structure of JSON-encoded response body for RequestPasswordReset HTTP request.
type ResetPasswordRequest ¶
type ResetPasswordRequest struct {
Password string `json:"password"`
}
ResetPasswordRequest is a structure that is passed as JSON-encoded body to ResetPassword HTTP request.
type Service ¶
type Service struct {
Client *apiClient.Client
}
Service implements gopherpit.com/gopherpit/services/user.Service interface.
func NewService ¶ added in v0.3.1
func NewService(c *apiClient.Client) *Service
NewService creates a new Service and injects user.ErrorRegistry in the API Client.
func (Service) Authenticate ¶
Authenticate validates a password of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}/authenticate. Request body is a JSON-encoded AuthenticateRequest instance. Expected response body is a JSON-encoded instance of AuthenticateResponse.
func (Service) ChangeEmail ¶
ChangeEmail changes an email of an existing User only if provided token is valid by making a HTTP POST request to {Client.Endpoint}/users/{ref}/email-change. Request body is a JSON-encoded ChangeEmailRequest instance.
func (Service) CreateUser ¶
CreateUser creates a new User instance by making a HTTP POST request to {Client.Endpoint}/users. Post body is a JSON-encoded user.Options instance.
func (Service) DeleteUser ¶
DeleteUser deletes an existing User by making a HTTP DELETE request to {Client.Endpoint}/users/{ref}.
func (Service) EmailChangeToken ¶
EmailChangeToken retrieves a token to change an email, if it exists, by making a HTTP GET request to {Client.Endpoint}/users/{ref}/email-change/{email}.
func (Service) RegisterUser ¶
func (s Service) RegisterUser(o *user.Options, password string, emailValidationDeadline time.Time) (u *user.User, emailValidationToken string, err error)
RegisterUser combines CreateUser SetPassword and RequestEmailChange into a single transaction to provide more convenient method for adding new users by making a HTTP POST request to {Client.Endpoint}/register. Request body is a JSON-encoded RegisterUserRequest instance. Expected response body is a JSON-encoded instance of RegisterUserResponse.
func (Service) RequestEmailChange ¶
func (s Service) RequestEmailChange(ref, email string, validationDeadline time.Time) (token string, err error)
RequestEmailChange starts a process of changing an email by returning a token that must be used in ChangeEmail to authorize email change by making a HTTP POST request to {Client.Endpoint}/users/{ref}/email-change-request. Request body is a JSON-encoded RequestEmailChangeRequest instance. Expected response body is a JSON-encoded instance of RequestEmailChangeResponse.
func (Service) RequestPasswordReset ¶
RequestPasswordReset starts a process of reseting a password by providing a token that must be used in ResetPassword to authorize password reset by making a HTTP POST request to {Client.Endpoint}/users/{ref}/password-reset-request. Expected response body is a JSON-encoded instance of RequestPasswordResetResponse.
func (Service) ResetPassword ¶
ResetPassword changes a password of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}/password-reset. Request body is a JSON-encoded ResetPasswordRequest instance.
func (Service) SetPassword ¶
SetPassword changes a password of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}/password. Request body is a JSON-encoded SetPasswordRequest instance.
func (Service) UpdateUser ¶
UpdateUser changes the data of an existing User by making a HTTP POST request to {Client.Endpoint}/users/{ref}. Post body is a JSON-encoded user.Options instance.
func (Service) User ¶
User retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users/{ref}.
func (Service) UserByEmail ¶
UserByEmail retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users-by-email/{email}.
func (Service) UserByID ¶
UserByID retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users-by-id/{id}.
func (Service) UserByUsername ¶
UserByUsername retrieves an existing User instance by making a HTTP GET request to {Client.Endpoint}/users-by-username/{username}.
func (Service) UsersByEmail ¶
UsersByEmail retrieves a paginated list of User instances ordered by Email values by making a HTTP GET request to {Client.Endpoint}/users-by-email?start={stardEmail}&limit={limit}.
func (Service) UsersByID ¶
UsersByID retrieves a paginated list of User instances ordered by ID values by making a HTTP GET request to {Client.Endpoint}/users-by-id?start={stardID}&limit={limit}.
func (Service) UsersByUsername ¶
UsersByUsername retrieves a paginated list of User instances ordered by Username values by making a HTTP GET request to {Client.Endpoint}/users-by-username?start={stardUsername}&limit={limit}.
type SetPasswordRequest ¶
type SetPasswordRequest struct {
Password string `json:"password"`
}
SetPasswordRequest is a structure that is passed as JSON-encoded body to SetPassword HTTP request.