Documentation
¶
Overview ¶
Package user managers all users in libredesk - agents and contacts.
Index ¶
- Variables
- func ChangeSystemUserPassword(ctx context.Context, db *sqlx.DB) error
- func CreateSystemUser(ctx context.Context, password string, db *sqlx.DB) error
- func IsStrongPassword(password string) bool
- type Manager
- func (u *Manager) CreateAgent(firstName, lastName, email string, roles []string) (models.User, error)
- func (u *Manager) CreateContact(user *models.User) error
- func (u *Manager) CreateNote(userID, authorID int, note string) (models.Note, error)
- func (u *Manager) DeleteNote(noteID int, contactID int) error
- func (u *Manager) GenerateAPIKey(userID int) (string, string, error)
- func (u *Manager) Get(id int, email, type_ string) (models.User, error)
- func (u *Manager) GetAgent(id int, email string) (models.User, error)
- func (u *Manager) GetAgentCachedOrLoad(id int) (models.User, error)
- func (u *Manager) GetAgentFromCache(id int) (models.User, bool)
- func (u *Manager) GetAgents() ([]models.UserCompact, error)
- func (u *Manager) GetAgentsCompact() ([]models.UserCompact, error)
- func (u *Manager) GetAllUsers(page, pageSize int, userType, order, orderBy string, filtersJSON string) ([]models.UserCompact, error)
- func (u *Manager) GetContact(id int, email string) (models.User, error)
- func (u *Manager) GetContacts(page, pageSize int, order, orderBy string, filtersJSON string) ([]models.UserCompact, error)
- func (u *Manager) GetNote(id int) (models.Note, error)
- func (u *Manager) GetNotes(id int) ([]models.Note, error)
- func (u *Manager) GetSystemUser() (models.User, error)
- func (u *Manager) InvalidateAgentCache(id int)
- func (u *Manager) InvalidateAllAgentCache()
- func (u *Manager) MonitorAgentAvailability(ctx context.Context)
- func (u *Manager) ResetPassword(token, password string) error
- func (u *Manager) RevokeAPIKey(userID int) error
- func (u *Manager) SetResetPasswordToken(id int) (string, error)
- func (u *Manager) SoftDeleteAgent(id int) error
- func (u *Manager) ToggleEnabled(id int, typ string, enabled bool) error
- func (u *Manager) UpdateAgent(id int, firstName, lastName, email string, roles []string, enabled bool, ...) error
- func (u *Manager) UpdateAvailability(id int, status string) error
- func (u *Manager) UpdateAvatar(id int, path string) error
- func (u *Manager) UpdateContact(id int, user models.User) error
- func (u *Manager) UpdateCustomAttributes(id int, customAttributes map[string]any) error
- func (u *Manager) UpdateLastActive(id int) error
- func (u *Manager) UpdateLastLoginAt(id int) error
- func (u *Manager) ValidateAPIKey(apiKey, apiSecret string) (models.User, error)
- func (u *Manager) VerifyPassword(email string, password []byte) (models.User, error)
- type Opts
Constants ¶
This section is empty.
Variables ¶
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 ¶
ChangeSystemUserPassword updates the system user's password with a newly prompted one.
func CreateSystemUser ¶
CreateSystemUser creates a system user with the provided password or a random one.
func IsStrongPassword ¶
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 (*Manager) CreateAgent ¶
func (u *Manager) CreateAgent(firstName, lastName, email string, roles []string) (models.User, error)
CreateAgent creates a new agent user.
func (*Manager) CreateContact ¶
CreateContact creates a new contact user.
func (*Manager) CreateNote ¶
CreateNote creates a new note for a user.
func (*Manager) DeleteNote ¶
DeleteNote deletes a note for a user.
func (*Manager) GenerateAPIKey ¶
GenerateAPIKey generates a new API key and secret for a user
func (*Manager) GetAgent ¶
GetAgent retrieves an agent by ID and also caches it for future requests.
func (*Manager) GetAgentCachedOrLoad ¶
GetAgentCachedOrLoad retrieves an agent from cache, falling back to DB if not cached.
func (*Manager) GetAgentFromCache ¶
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 ¶
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) GetSystemUser ¶
GetSystemUser retrieves the system user.
func (*Manager) InvalidateAgentCache ¶
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 ¶
MonitorAgentAvailability continuously checks for user activity and sets them offline if inactive for more than 5 minutes.
func (*Manager) ResetPassword ¶
ResetPassword sets a password for a given user's reset password token.
func (*Manager) RevokeAPIKey ¶
RevokeAPIKey deactivates the API key for a user
func (*Manager) SetResetPasswordToken ¶
SetResetPasswordToken sets a reset password token for an user and returns the token.
func (*Manager) SoftDeleteAgent ¶
SoftDeleteAgent soft deletes an agent by ID.
func (*Manager) ToggleEnabled ¶
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 ¶
UpdateAvailability updates the availability status of an user.
func (*Manager) UpdateAvatar ¶
UpdateAvatar updates the user avatar.
func (*Manager) UpdateContact ¶
UpdateContact updates a contact in the database.
func (*Manager) UpdateCustomAttributes ¶
UpdateCustomAttributes updates the custom attributes of an user.
func (*Manager) UpdateLastActive ¶
UpdateLastActive updates the last active timestamp of an user.
func (*Manager) UpdateLastLoginAt ¶
UpdateLastLoginAt updates the last login timestamp of an user.
func (*Manager) ValidateAPIKey ¶
ValidateAPIKey validates API key and secret and returns the user