user

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package user managers all users in libredesk - agents and contacts.

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrPasswordTooLong is returned when the password passed to
	// GenerateFromPassword is too long (i.e. > 72 bytes).
	ErrPasswordTooLong = errors.New("password length exceeds 72 bytes")

	PasswordHint = fmt.Sprintf("Password must be %d-%d characters long should contain at least one uppercase letter, one lowercase letter, one number, and one special character.", minPassword, maxPassword)
)

Functions

func ChangeSystemUserPassword

func ChangeSystemUserPassword(ctx context.Context, db *sqlx.DB) error

ChangeSystemUserPassword updates the system user's password with a newly prompted one.

func CreateSystemUser

func CreateSystemUser(ctx context.Context, password string, db *sqlx.DB) error

CreateSystemUser creates a system user with the provided password or a random one.

func IsStrongPassword

func IsStrongPassword(password string) bool

IsStrongPassword checks if the password meets the required strength for system user.

Types

type Manager

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

Manager handles user-related operations.

func New

func New(i18n *i18n.I18n, opts Opts) (*Manager, error)

New creates and returns a new instance of the Manager.

func (*Manager) CreateAgent

func (u *Manager) CreateAgent(firstName, lastName, email string, roles []string) (models.User, error)

CreateAgent creates a new agent user.

func (*Manager) CreateContact

func (u *Manager) CreateContact(user *models.User) error

CreateContact creates a new contact user.

func (*Manager) CreateNote

func (u *Manager) CreateNote(userID, authorID int, note string) (models.Note, error)

CreateNote creates a new note for a user.

func (*Manager) DeleteNote

func (u *Manager) DeleteNote(noteID int, contactID int) error

DeleteNote deletes a note for a user.

func (*Manager) GenerateAPIKey

func (u *Manager) GenerateAPIKey(userID int) (string, string, error)

GenerateAPIKey generates a new API key and secret for a user

func (*Manager) Get

func (u *Manager) Get(id int, email, type_ string) (models.User, error)

Get retrieves an user by ID or email.

func (*Manager) GetAgent

func (u *Manager) GetAgent(id int, email string) (models.User, error)

GetAgent retrieves an agent by ID and also caches it for future requests.

func (*Manager) GetAgentCachedOrLoad

func (u *Manager) GetAgentCachedOrLoad(id int) (models.User, error)

GetAgentCachedOrLoad retrieves an agent from cache, falling back to DB if not cached.

func (*Manager) GetAgentFromCache

func (u *Manager) GetAgentFromCache(id int) (models.User, bool)

GetAgentFromCache retrieves an agent from the cache by ID.

func (*Manager) GetAgents

func (u *Manager) GetAgents() ([]models.UserCompact, error)

GetAllAgents returns a list of all agents.

func (*Manager) GetAgentsCompact

func (u *Manager) GetAgentsCompact() ([]models.UserCompact, error)

GetAgentsCompact returns a compact list of agents with limited fields.

func (*Manager) GetAllUsers

func (u *Manager) GetAllUsers(page, pageSize int, userType, order, orderBy string, filtersJSON string) ([]models.UserCompact, error)

GetAllUsers returns a list of all users.

func (*Manager) GetContact

func (u *Manager) GetContact(id int, email string) (models.User, error)

GetContact retrieves a contact by ID.

func (*Manager) GetContacts

func (u *Manager) GetContacts(page, pageSize int, order, orderBy string, filtersJSON string) ([]models.UserCompact, error)

GetAllContacts returns a list of all contacts.

func (*Manager) GetNote

func (u *Manager) GetNote(id int) (models.Note, error)

GetNote returns a note by its ID.

func (*Manager) GetNotes

func (u *Manager) GetNotes(id int) ([]models.Note, error)

GetNotes returns all notes for a user.

func (*Manager) GetSystemUser

func (u *Manager) GetSystemUser() (models.User, error)

GetSystemUser retrieves the system user.

func (*Manager) InvalidateAgentCache

func (u *Manager) InvalidateAgentCache(id int)

InvalidateAgentCache invalidates the agent cache for a specific agent ID.

func (*Manager) InvalidateAllAgentCache

func (u *Manager) InvalidateAllAgentCache()

InvalidateAllAgentCache clears the entire agent cache.

func (*Manager) MonitorAgentAvailability

func (u *Manager) MonitorAgentAvailability(ctx context.Context)

MonitorAgentAvailability continuously checks for user activity and sets them offline if inactive for more than 5 minutes.

func (*Manager) ResetPassword

func (u *Manager) ResetPassword(token, password string) error

ResetPassword sets a password for a given user's reset password token.

func (*Manager) RevokeAPIKey

func (u *Manager) RevokeAPIKey(userID int) error

RevokeAPIKey deactivates the API key for a user

func (*Manager) SetResetPasswordToken

func (u *Manager) SetResetPasswordToken(id int) (string, error)

SetResetPasswordToken sets a reset password token for an user and returns the token.

func (*Manager) SoftDeleteAgent

func (u *Manager) SoftDeleteAgent(id int) error

SoftDeleteAgent soft deletes an agent by ID.

func (*Manager) ToggleEnabled

func (u *Manager) ToggleEnabled(id int, typ string, enabled bool) error

ToggleEnabled toggles the enabled status of an user.

func (*Manager) UpdateAgent

func (u *Manager) UpdateAgent(id int, firstName, lastName, email string, roles []string, enabled bool, availabilityStatus, newPassword string) error

UpdateAgent updates an agent with individual field parameters

func (*Manager) UpdateAvailability

func (u *Manager) UpdateAvailability(id int, status string) error

UpdateAvailability updates the availability status of an user.

func (*Manager) UpdateAvatar

func (u *Manager) UpdateAvatar(id int, path string) error

UpdateAvatar updates the user avatar.

func (*Manager) UpdateContact

func (u *Manager) UpdateContact(id int, user models.User) error

UpdateContact updates a contact in the database.

func (*Manager) UpdateCustomAttributes

func (u *Manager) UpdateCustomAttributes(id int, customAttributes map[string]any) error

UpdateCustomAttributes updates the custom attributes of an user.

func (*Manager) UpdateLastActive

func (u *Manager) UpdateLastActive(id int) error

UpdateLastActive updates the last active timestamp of an user.

func (*Manager) UpdateLastLoginAt

func (u *Manager) UpdateLastLoginAt(id int) error

UpdateLastLoginAt updates the last login timestamp of an user.

func (*Manager) ValidateAPIKey

func (u *Manager) ValidateAPIKey(apiKey, apiSecret string) (models.User, error)

ValidateAPIKey validates API key and secret and returns the user

func (*Manager) VerifyPassword

func (u *Manager) VerifyPassword(email string, password []byte) (models.User, error)

VerifyPassword authenticates an user by email and password, returning the user if successful.

type Opts

type Opts struct {
	DB *sqlx.DB
	Lo *logf.Logger
}

Opts contains options for initializing the Manager.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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