userservice

package
v0.0.0-...-0f16109 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const DemoUsername = "quickconnect"

Variables

This section is empty.

Functions

func HashPassword

func HashPassword(password string) (string, error)

func VerifyPassword

func VerifyPassword(hashedPassword, password string) bool

Types

type ChangePasswordRequest

type ChangePasswordRequest struct {
	OldPassword string `json:"old_password"`
	NewPassword string `json:"new_password"`
}

type Config

type Config struct {
	UserIDCacheExpiration time.Duration `koanf:"user_id_cache_expiration"`
	PasswordDefaultLength int           `koanf:"password_default_length"`
}

type ExternalUserRepository

type ExternalUserRepository interface {
	IsExistUserIDFromExternalUserID(ctx context.Context, externalUserID string) (bool, error)
	GetUserIDFromExternalUserID(ctx context.Context, externalUserID string) (types.ID, error)
	CreateUserIDFromExternalUserID(ctx context.Context, externalUserID string, userID types.ID) error
}

type IdentifyClientRequest

type IdentifyClientRequest struct {
	ExternalUserID string `json:"user_id"`
	Fullname       string `json:"fullname"`
	Email          string `json:"email"`
	PhoneNumber    string `json:"phone_number"`
}

type IdentifyClientResponse

type IdentifyClientResponse struct {
	User

	QCToken string `json:"qc_token"`
}

type ListUserRequest

type ListUserRequest struct {
	Username  string               `json:"username"`
	Roles     []types.Role         `json:"roles"`
	Paginated paginate.RequestBase `json:"paginated"`
}

type ListUserResponse

type ListUserResponse struct {
	Results  []User                `json:"results"`
	Paginate paginate.ResponseBase `json:"paginate"`
}

type RegisterGuestUserRequest

type RegisterGuestUserRequest struct {
	Fullname    string `json:"fullname"`
	Email       string `json:"email"`
	PhoneNumber string `json:"phone_number"`
}

type RegisterGuestUserResponse

type RegisterGuestUserResponse struct {
	User

	QCToken string `json:"qc_token"`
}

type Repository

type Repository interface {
	IsExistUserByUsername(ctx context.Context, username string) (bool, error)
	IsExistUserByID(ctx context.Context, userID types.ID) (bool, error)
	GetUserByUsername(ctx context.Context, username string) (User, error)
	GetUserByID(ctx context.Context, userID types.ID) (User, error)
	CreateUser(ctx context.Context, req UserCreateRequest) (User, error)
	GetUserList(ctx context.Context, paginated paginate.RequestBase, username string,
		roles []types.Role) ([]User, paginate.ResponseBase, error)
	DeleteUser(ctx context.Context, userID types.ID) error
	UpdateUser(ctx context.Context, userID types.ID, req UserUpdateFromSuperuserRequest) error
	GetUserHashedPassword(ctx context.Context, userID types.ID) (string, error)
	ChangePassword(ctx context.Context, userID types.ID, hashedPassword string) error
	GetUserInfoByID(ctx context.Context, userID types.ID) (UserInfoResponse, error)
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

func New

func New(cfg Config, tokenSvc TokenSvc, vld Validate, repo Repository, externalUserRepo ExternalUserRepository, logger *slog.Logger,
	cache *cachemanager.CacheManager) Service

func (Service) ChangePassword

func (s Service) ChangePassword(ctx context.Context, userID types.ID, req ChangePasswordRequest) error

func (Service) CreateUser

func (Service) GetUserIDFromExternalUserID

func (s Service) GetUserIDFromExternalUserID(ctx context.Context, externalUserID string) (types.ID, error)

func (Service) IdentifyClient

func (Service) Login

func (Service) RefreshToken

func (s Service) RefreshToken(ctx context.Context, refreshToken string) (*tokenservice.TokenGenerateResponse, error)

func (Service) RegisterGuestUser

func (Service) UpdateGuestUser

func (s Service) UpdateGuestUser(ctx context.Context, userID types.ID, req UpdateGuestUserRequest) (UpdateGuestUserResponse, error)

func (Service) UserDelete

func (s Service) UserDelete(ctx context.Context, userID types.ID) error

func (Service) UserInfo

func (s Service) UserInfo(ctx context.Context, userID types.ID) (UserInfoResponse, error)

UserInfo retrieves User info for client & support We don't check user exists.

func (Service) UserList

func (s Service) UserList(ctx context.Context, req ListUserRequest) (ListUserResponse, error)

func (Service) UserProfile

func (s Service) UserProfile(ctx context.Context, userID types.ID) (UserProfileResponse, error)

func (Service) UserUpdateFromOwn

func (s Service) UserUpdateFromOwn(ctx context.Context, userID types.ID, req UserUpdateFromOwnRequest) (UserUpdateResponse, error)

func (Service) UserUpdateFromSuperuser

func (s Service) UserUpdateFromSuperuser(ctx context.Context, userID types.ID,
	req UserUpdateFromSuperuserRequest) (UserUpdateResponse, error)

type TokenSvc

type TokenSvc interface {
	GenerateTokenPair(userID types.ID, roles []types.Role) (*tokenservice.TokenGenerateResponse, error)
	GenerateGuestToken(ctx context.Context, userID types.ID) (string, error)
	GenerateClientToken(ctx context.Context, userID types.ID, roles []types.Role) (string, error)
	ValidateToken(tokenString string) (*types.UserClaims, error)
}

type UpdateGuestUserRequest

type UpdateGuestUserRequest struct {
	Fullname    string `json:"fullname"`
	Email       string `json:"email"`
	PhoneNumber string `json:"phone_number"`
}

type UpdateGuestUserResponse

type UpdateGuestUserResponse struct {
	User
}

type User

type User struct {
	ID             types.ID     `json:"id"`
	Username       string       `json:"username"`
	HashedPassword string       `json:"-"`
	Fullname       string       `json:"fullname"`
	Email          string       `json:"email"`
	PhoneNumber    string       `json:"phone_number"`
	Avatar         string       `json:"avatar"`
	Roles          []types.Role `json:"roles"`
	LastOnlineAt   time.Time    `json:"last_online_at"`
}

type UserCreateRequest

type UserCreateRequest struct {
	ID          types.ID     `json:"-"`
	Username    string       `json:"username"`
	Password    string       `json:"password"`
	Fullname    string       `json:"fullname"`
	Email       string       `json:"email"`
	PhoneNumber string       `json:"phone_number"`
	Roles       []types.Role `json:"roles"`
}

type UserCreateResponse

type UserCreateResponse struct {
	User
}

type UserIDCacheValue

type UserIDCacheValue struct {
	UserID types.ID `json:"user_id"`
}

type UserInfoResponse

type UserInfoResponse struct {
	ID           types.ID  `json:"id"`
	Fullname     string    `json:"fullname"`
	Username     string    `json:"username"`
	Email        string    `json:"email"`
	PhoneNumber  string    `json:"phone_number"`
	Avatar       string    `json:"avatar"`
	LastOnlineAt time.Time `json:"last_online_at"`
}

type UserLoginRequest

type UserLoginRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type UserLoginResponse

type UserLoginResponse struct {
	User  User                               `json:"user"`
	Token tokenservice.TokenGenerateResponse `json:"token"`
}

type UserProfileResponse

type UserProfileResponse struct {
	User
}

type UserUpdateFromOwnRequest

type UserUpdateFromOwnRequest struct {
	Username    string `json:"username"`
	Fullname    string `json:"fullname"`
	Email       string `json:"email"`
	PhoneNumber string `json:"phone_number"`
}

type UserUpdateFromSuperuserRequest

type UserUpdateFromSuperuserRequest struct {
	Username    string       `json:"username"`
	Fullname    string       `json:"fullname"`
	Email       string       `json:"email"`
	PhoneNumber string       `json:"phone_number"`
	Roles       []types.Role `json:"roles"`
}

type UserUpdateResponse

type UserUpdateResponse struct {
	User
}

type Validate

type Validate struct {
	// contains filtered or unexported fields
}

func NewValidate

func NewValidate(t *translation.Translate) Validate

func (Validate) ChangePasswordRequest

func (v Validate) ChangePasswordRequest(req ChangePasswordRequest) error

func (Validate) UserUpdateFromSuperuserRequest

func (v Validate) UserUpdateFromSuperuserRequest(req UserUpdateFromSuperuserRequest) error

func (Validate) ValidateIdentifyClientRequest

func (v Validate) ValidateIdentifyClientRequest(req IdentifyClientRequest) error

func (Validate) ValidateListUserRequest

func (v Validate) ValidateListUserRequest(req ListUserRequest) error

func (Validate) ValidateLoginRequest

func (v Validate) ValidateLoginRequest(req UserLoginRequest) error

func (Validate) ValidateRegisterGuestUserRequest

func (v Validate) ValidateRegisterGuestUserRequest(req RegisterGuestUserRequest) error

func (Validate) ValidateUpdateGuestUserRequest

func (v Validate) ValidateUpdateGuestUserRequest(req UpdateGuestUserRequest) error

func (Validate) ValidateUserCreateRequest

func (v Validate) ValidateUserCreateRequest(req UserCreateRequest) error

Jump to

Keyboard shortcuts

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