user

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

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

func NewHTTP

func NewHTTP(svc Service, auth model.Auth, eg *echo.Group)

NewHTTP creates new user http service

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 ListResp

type ListResp struct {
	Data       []*model.User `json:"data"`
	TotalCount int64         `json:"total_count"`
}

ListResp contains list of users and current page number response

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 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 New

func New(db *gorm.DB, udb MyDB, rbacSvc rbac.Intf, cr Crypter) *User

New creates new 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) Delete

func (s *User) Delete(ctx context.Context, authUsr *model.AuthUser, id int) error

Delete deletes a user

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

func (*User) Me

func (s *User) Me(ctx context.Context, authUsr *model.AuthUser) (*model.User, error)

Me returns authenticated user

func (*User) Update

func (s *User) Update(ctx context.Context, authUsr *model.AuthUser, id int, data UpdateData) (*model.User, error)

Update updates user information

func (*User) View

func (s *User) View(ctx context.Context, authUsr *model.AuthUser, id int) (*model.User, error)

View returns single user

Jump to

Keyboard shortcuts

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