Documentation ¶
Overview ¶
Package user contains user related CRUD functionality.
Index ¶
- Variables
- type Info
- type NewUser
- type UpdateUser
- type User
- func (u User) Authenticate(ctx context.Context, traceID string, now time.Time, email, password string) (auth.Claims, error)
- func (u User) Create(ctx context.Context, traceID string, nu NewUser, now time.Time) (Info, error)
- func (u User) Delete(ctx context.Context, traceID string, userID string) error
- func (u User) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)
- func (u User) QueryByEmail(ctx context.Context, traceID string, claims auth.Claims, email string) (Info, error)
- func (u User) QueryByID(ctx context.Context, traceID string, claims auth.Claims, userID string) (Info, error)
- func (u User) Update(ctx context.Context, traceID string, claims auth.Claims, userID string, ...) error
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is used when a specific User is requested but does not exist. ErrNotFound = errors.New("not found") // ErrInvalidID occurs when an ID is not in a valid form. ErrInvalidID = errors.New("ID is not in its proper form") // ErrAuthenticationFailure occurs when a user attempts to authenticate but // anything goes wrong. ErrAuthenticationFailure = errors.New("authentication failed") // ErrForbidden occurs when a user tries to do something that is forbidden to them according to our access control policies. ErrForbidden = errors.New("attempted action is not allowed") // PasswordSalt is the salt value which will be addedd to passwords during the hashing process for extra security. PasswordSalt = "joireu98ytu98grHROIHGWJREOIJOIJroJ5Y09JRATHJOIHJj5y09aeoirjroiejjrtjhJROIJIJyjHJroisjh509e5e0jte0jhreoijtkjrtrej9yg" // EmailSalt is the salt value which will be addedd to emails during the hashing process for extra security. // Emails are hashed for GDPR compliance. EmailSalt = "nbkjvnKJNBKJNFNKFbnkfnte80bnfdb5e5090hetaoijknbnjvNKSFBfnkjneinF8I*H$%IHIGRiuhgIUNGEibus8b8s9rnbnrwengiubi4w9898U8H" )
var Issuer = "MB Appiness Solutions"
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct { ID string `db:"user_id" json:"id"` Email string `db:"email" json:"email"` Roles pq.StringArray `db:"roles" json:"roles"` PasswordHash []byte `db:"password_hash" json:"-"` DateCreated time.Time `db:"date_created" json:"date_created"` DateUpdated time.Time `db:"date_updated" json:"date_updated"` }
Info represents an individual user.
type NewUser ¶
type NewUser struct { Email string `json:"email" validate:"required,email"` Roles []string `json:"roles" validate:"required"` Password string `json:"password" validate:"required"` PasswordConfirm string `json:"password_confirm" validate:"eqfield=Password"` }
NewUser contains information needed to create a new User.
type UpdateUser ¶
type UpdateUser struct { Email *string `json:"email" validate:"omitempty,email"` Roles []string `json:"roles"` Password *string `json:"password"` PasswordConfirm *string `json:"password_confirm" validate:"omitempty,eqfield=Password"` }
UpdateUser defines what information may be provided to modify an existing User. All fields are optional so clients 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 {
// contains filtered or unexported fields
}
User manages the set of API's for user access.
func (User) Authenticate ¶
func (u User) Authenticate(ctx context.Context, traceID string, now time.Time, email, password string) (auth.Claims, error)
Authenticate finds a user by their email and verifies their password. On success it returns a Claims Info representing this user. The claims can be used to generate a token for future authentication.
func (User) Query ¶
func (u User) Query(ctx context.Context, traceID string, pageNumber int, rowsPerPage int) ([]Info, error)
Query retrieves a list of existing users from the database.
func (User) QueryByEmail ¶
func (u User) QueryByEmail(ctx context.Context, traceID string, claims auth.Claims, email string) (Info, error)
QueryByEmail gets the specified user from the database by email.