Documentation
¶
Index ¶
- Constants
- Variables
- func Module(scope string) fx.Option
- type ListUsersRequest
- type ListUsersResp
- type Params
- type User
- type UserConfig
- type UserManager
- func (m *UserManager) Authenticate(ctx context.Context, identifier string, password string) (*User, error)
- func (m *UserManager) Create(ctx context.Context, cfg *UserConfig) (*User, error)
- func (m *UserManager) Delete(ctx context.Context, userID string) error
- func (m *UserManager) Get(ctx context.Context, userID string) (*User, error)
- func (m *UserManager) GetByEmail(ctx context.Context, email string) (*User, error)
- func (m *UserManager) GetByUsername(ctx context.Context, username string) (*User, error)
- func (m *UserManager) InitDefaultConfigs()
- func (m *UserManager) List(ctx context.Context, req *ListUsersRequest, qh *queryhelper.QueryHelper) (*ListUsersResp, error)
- func (m *UserManager) OnStart(ctx context.Context) error
- func (m *UserManager) OnStop(ctx context.Context) error
- func (m *UserManager) Update(ctx context.Context, userID string, cfg *UserConfig) (*User, error)
- func (m *UserManager) UpdatePassword(ctx context.Context, userID string, newPassword string) error
- func (m *UserManager) VerifyPassword(ctx context.Context, userID string, password string) error
Constants ¶
View Source
const ( DefaultAdminUsername = "admin" DefaultAdminEmail = "admin@localhost" DefaultAdminPassword = "1qaz@WSX" )
Default admin credentials
View Source
const ModuleName = "UserManager"
Variables ¶
View Source
var ( ErrNotFound = errors.New("user not found") ErrUsernameExists = errors.New("username already exists") ErrEmailExists = errors.New("email already exists") ErrInvalidInput = errors.New("invalid input") ErrInvalidPassword = errors.New("invalid password") ErrInvalidCredentials = errors.New("invalid credentials") ErrOperationFailed = errors.New("operation failed") ErrPasswordTooShort = errors.New("password must be at least 8 characters") )
View Source
var DefaultQuerySettings = &queryhelper.QuerySettings{ AllowedOrderBy: []string{"created_at", "updated_at", "username", "email", "last_login_at"}, AllowedSearch: []string{"username", "email", "display_name"}, AllowedFilters: map[string][]string{ "status": {"=", "!=", "IN"}, "role": {"=", "!=", "IN"}, "username": {"=", "LIKE"}, "email": {"=", "LIKE"}, }, }
QueryHelper settings
Functions ¶
Types ¶
type ListUsersRequest ¶
type ListUsersRequest struct {
Username *string
Email *string
Role *string // Filter by role (checks if user has this role)
Status *string
}
ListUsersRequest filter conditions for list query
type ListUsersResp ¶
type ListUsersResp struct {
Data []*User
QueryHelper *queryhelper.QueryHelper
}
ListUsersResp list query response
type User ¶
type User struct {
ID string
Username string
Email string
DisplayName string
Roles []string
Status string
LastLoginAt *time.Time
CreatedAt time.Time
UpdatedAt time.Time
}
User public user structure (password hash is never exposed)
type UserConfig ¶
type UserConfig struct {
Username string
Email string
Password string // Plain text password (will be hashed)
DisplayName string
Roles []string // Multiple roles
Status string
}
UserConfig configuration for create/update
type UserManager ¶
func (*UserManager) Authenticate ¶
func (m *UserManager) Authenticate(ctx context.Context, identifier string, password string) (*User, error)
Authenticate authenticates a user by username/email and password
func (*UserManager) Create ¶
func (m *UserManager) Create(ctx context.Context, cfg *UserConfig) (*User, error)
Create creates a new user with hashed password
func (*UserManager) Delete ¶
func (m *UserManager) Delete(ctx context.Context, userID string) error
Delete deletes a user
func (*UserManager) GetByEmail ¶
GetByEmail retrieves a user by email
func (*UserManager) GetByUsername ¶
GetByUsername retrieves a user by username
func (*UserManager) InitDefaultConfigs ¶
func (m *UserManager) InitDefaultConfigs()
func (*UserManager) List ¶
func (m *UserManager) List(ctx context.Context, req *ListUsersRequest, qh *queryhelper.QueryHelper) (*ListUsersResp, error)
List queries users with pagination, search, sorting, and filtering
func (*UserManager) Update ¶
func (m *UserManager) Update(ctx context.Context, userID string, cfg *UserConfig) (*User, error)
Update updates a user (excluding password)
func (*UserManager) UpdatePassword ¶
UpdatePassword updates a user's password
func (*UserManager) VerifyPassword ¶
VerifyPassword verifies if the provided password matches the user's stored password
Click to show internal directories.
Click to hide internal directories.