Documentation
¶
Index ¶
- Variables
- func NewHTTP(svc Service, auth model.Auth, eg *echo.Group)
- type CreationData
- type Crypter
- type HTTP
- type ListResp
- type MyDB
- type PasswordChangeData
- type Service
- type UpdateData
- type User
- func (s *User) ChangePassword(ctx context.Context, authUsr *model.AuthUser, data PasswordChangeData) error
- func (s *User) Create(ctx context.Context, authUsr *model.AuthUser, data CreationData) (*model.User, error)
- func (s *User) Delete(ctx context.Context, authUsr *model.AuthUser, id int) error
- func (s *User) List(ctx context.Context, authUsr *model.AuthUser, lq *dbutil.ListQueryCondition, ...) ([]*model.User, error)
- func (s *User) Me(ctx context.Context, authUsr *model.AuthUser) (*model.User, error)
- func (s *User) Update(ctx context.Context, authUsr *model.AuthUser, id int, data UpdateData) (*model.User, error)
- func (s *User) View(ctx context.Context, authUsr *model.AuthUser, id int) (*model.User, error)
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrIncorrectPassword = server.NewHTTPError(http.StatusBadRequest, "INCORRECT_PASSWORD", "Incorrect old password") ErrUserNotFound = server.NewHTTPError(http.StatusBadRequest, "USER_NOTFOUND", "User not found") ErrUsernameExisted = server.NewHTTPValidationError("Username already existed") )
Custom errors
Functions ¶
Types ¶
type CreationData ¶
type CreationData struct {
Username string `json:"username" validate:"required,min=3"`
Password string `json:"password" validate:"required,min=8"`
FirstName string `json:"first_name" validate:"required"`
LastName string `json:"last_name" validate:"required"`
Email string `json:"email" validate:"required,email"`
Mobile string `json:"mobile" validate:"required,mobile"`
Role string `json:"role" validate:"required"`
Blocked bool `json:"blocked"`
}
CreationData contains user data from json request
type Crypter ¶
type Crypter interface {
CompareHashAndPassword(hasedPwd string, rawPwd string) bool
HashPassword(string) string
}
Crypter represents security interface
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
HTTP represents user http service
type MyDB ¶
type MyDB interface {
dbutil.Intf
FindByUsername(context.Context, *gorm.DB, string) (*model.User, error)
}
MyDB represents user repository interface
type PasswordChangeData ¶
type PasswordChangeData struct {
OldPassword string `json:"old_password" validate:"required"`
NewPassword string `json:"new_password" validate:"required,min=8"`
NewPasswordConfirm string `json:"new_password_confirm" validate:"required,eqfield=NewPassword"`
}
PasswordChangeData contains password change request
type Service ¶
type Service interface {
Create(context.Context, *model.AuthUser, CreationData) (*model.User, error)
View(context.Context, *model.AuthUser, int) (*model.User, error)
List(context.Context, *model.AuthUser, *dbutil.ListQueryCondition, *int64) ([]*model.User, error)
Update(context.Context, *model.AuthUser, int, UpdateData) (*model.User, error)
Delete(context.Context, *model.AuthUser, int) error
Me(context.Context, *model.AuthUser) (*model.User, error)
ChangePassword(context.Context, *model.AuthUser, PasswordChangeData) error
}
Service represents user application interface
type UpdateData ¶
type UpdateData struct {
FirstName *string `json:"first_name,omitempty"`
LastName *string `json:"last_name,omitempty"`
Email *string `json:"email,omitempty" validate:"omitempty,email"`
Mobile *string `json:"mobile,omitempty" validate:"omitempty,mobile"`
Role *string `json:"role,omitempty"`
Blocked *bool `json:"blocked,omitempty"`
}
UpdateData contains user data from json request
type User ¶
type User struct {
// contains filtered or unexported fields
}
User represents user application service
func (*User) ChangePassword ¶
func (s *User) ChangePassword(ctx context.Context, authUsr *model.AuthUser, data PasswordChangeData) error
ChangePassword changes authenticated user password
func (*User) Create ¶
func (s *User) Create(ctx context.Context, authUsr *model.AuthUser, data CreationData) (*model.User, error)
Create creates a new user account
func (*User) List ¶
func (s *User) List(ctx context.Context, authUsr *model.AuthUser, lq *dbutil.ListQueryCondition, count *int64) ([]*model.User, error)
List returns list of users
Click to show internal directories.
Click to hide internal directories.