Documentation ¶
Overview ¶
Package users contains the domain concept definitions needed to support Magistrala users service functionality.
This package defines the core domain concepts and types necessary to handle users in the context of a Magistrala users service. It abstracts the underlying complexities of user management and provides a structured approach to working with users.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var CurrentUser = UserInfo{}
Functions ¶
func NewDeleteHandler ¶ added in v1.0.1
func NewDeleteHandler(ctx context.Context, clients postgres.Repository, auth magistrala.AuthServiceClient, defCheckInterval, deleteAfter time.Duration, logger *slog.Logger)
Types ¶
type Credentials ¶
type Credentials struct {
Identity string `json:"identity"`
}
Credentials 结构体表示credentials对象
type Emailer ¶
type Emailer interface { // SendPasswordReset sends an email to the user with a link to reset the password. SendPasswordReset(To []string, host, user, token string) error }
Emailer wrapper around the email.
type Hasher ¶
type Hasher interface { // Hash generates the hashed string from plain-text. Hash(string) (string, error) // Compare compares plain-text version to the hashed one. An error should // indicate failed comparison. Compare(string, string) error }
Hasher specifies an API for generating hashes of an arbitrary textual content.
type Service ¶
type Service interface { // RegisterClient creates new client. In case of the failed registration, a // non-nil error value is returned. RegisterClient(ctx context.Context, token string, client clients.Client) (clients.Client, error) // ViewClient retrieves client info for a given client ID and an authorized token. ViewClient(ctx context.Context, token, id string) (clients.Client, error) // ViewProfile retrieves client info for a given token. ViewProfile(ctx context.Context, token string) (clients.Client, error) // ListClients retrieves clients list for a valid auth token. ListClients(ctx context.Context, token string, pm clients.Page) (clients.ClientsPage, error) // ListMembers retrieves everything that is assigned to a group/thing identified by objectID. ListMembers(ctx context.Context, token, objectKind, objectID string, pm clients.Page) (clients.MembersPage, error) // UpdateClient updates the client's name and metadata. UpdateClient(ctx context.Context, token string, client clients.Client) (clients.Client, error) // UpdateClientTags updates the client's tags. UpdateClientTags(ctx context.Context, token string, client clients.Client) (clients.Client, error) // UpdateClientIdentity updates the client's identity. UpdateClientIdentity(ctx context.Context, token, id, identity string) (clients.Client, error) // GenerateResetToken email where mail will be sent. // host is used for generating reset link. GenerateResetToken(ctx context.Context, email, host string) error // UpdateClientSecret updates the client's secret. UpdateClientSecret(ctx context.Context, token, oldSecret, newSecret string) (clients.Client, error) // ResetSecret change users secret in reset flow. // token can be authentication token or secret reset token. ResetSecret(ctx context.Context, resetToken, secret string) error // SendPasswordReset sends reset password link to email. SendPasswordReset(ctx context.Context, host, email, user, token string) error // UpdateClientRole updates the client's Role. UpdateClientRole(ctx context.Context, token string, client clients.Client) (clients.Client, error) // EnableClient logically enableds the client identified with the provided ID. EnableClient(ctx context.Context, token, id string) (clients.Client, error) // DisableClient logically disables the client identified with the provided ID. DisableClient(ctx context.Context, token, id string) (clients.Client, error) // DeleteClient deletes client with given ID. DeleteClient(ctx context.Context, token, id string) error // Identify returns the client id from the given token. Identify(ctx context.Context, tkn string) (string, error) // IssueToken issues a new access and refresh token. IssueToken(ctx context.Context, identity, secret, domainID string) (*magistrala.Token, error) // RefreshToken refreshes expired access tokens. // After an access token expires, the refresh token is used to get // a new pair of access and refresh tokens. RefreshToken(ctx context.Context, accessToken, domainID string) (*magistrala.Token, error) // OAuthCallback handles the callback from any supported OAuth provider. // It processes the OAuth tokens and either signs in or signs up the user based on the provided state. OAuthCallback(ctx context.Context, state mgoauth2.State, client clients.Client) (*magistrala.Token, error) }
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
func NewService ¶
func NewService(crepo postgres.Repository, authClient magistrala.AuthServiceClient, emailer Emailer, hasher Hasher, idp magistrala.IDProvider, selfRegister bool) Service
NewService returns a new Users service implementation.
type TokenResponseBody ¶
type UserInfoResponseBody ¶
type UserInfoResponseBody struct { ID string `json:"id"` Name string `json:"name"` Credentials Credentials `json:"credentials"` Metadata map[string]interface{} `json:"metadata"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` UpdatedBy string `json:"updated_by"` Status string `json:"status"` }
UserInfo 结构体表示整个JSON对象
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations.
|
Package api contains API-related concerns: endpoint definitions, middlewares and all resource representations. |
Package emailer contains the domain concept definitions needed to support Magistrala users email service functionality.
|
Package emailer contains the domain concept definitions needed to support Magistrala users email service functionality. |
Package events provides the domain concept definitions needed to support Magistrala users service functionality.
|
Package events provides the domain concept definitions needed to support Magistrala users service functionality. |
Package hasher contains the domain concept definitions needed to support Magistrala users password hasher sub-service functionality.
|
Package hasher contains the domain concept definitions needed to support Magistrala users password hasher sub-service functionality. |
Package mocks contains mocks for testing purposes.
|
Package mocks contains mocks for testing purposes. |
Package postgres contains the database implementation of clients repository layer.
|
Package postgres contains the database implementation of clients repository layer. |
Package tracing provides tracing instrumentation for Magistrala Users service.
|
Package tracing provides tracing instrumentation for Magistrala Users service. |