Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrConflict indicates usage of the existing email during account // registration. ErrConflict = errors.New("email already taken") // ErrGroupConflict indicates group name already taken. ErrGroupConflict = errors.New("group already exists") // ErrMalformedEntity indicates malformed entity specification // (e.g. invalid username or password). ErrMalformedEntity = errors.New("malformed entity specification") // when accessing a protected resource. ErrUnauthorizedAccess = errors.New("missing or invalid credentials provided") // ErrNotFound indicates a non-existent entity request. ErrNotFound = errors.New("non-existent entity") // ErrUserNotFound indicates a non-existent user request. ErrUserNotFound = errors.New("non-existent user") // ErrScanMetadata indicates problem with metadata in db. ErrScanMetadata = errors.New("failed to scan metadata") // ErrMissingEmail indicates missing email for password reset request. ErrMissingEmail = errors.New("missing email for password reset") // ErrMissingResetToken indicates malformed or missing reset token // for reseting password. ErrMissingResetToken = errors.New("missing reset token") // ErrRecoveryToken indicates error in generating password recovery token. ErrRecoveryToken = errors.New("failed to generate password recovery token") // ErrGetToken indicates error in getting signed token. ErrGetToken = errors.New("failed to fetch signed token") // ErrCreateUser indicates error in creating user. ErrCreateUser = errors.New("failed to create user") // ErrCreateGroup indicates error in creating group. ErrCreateGroup = errors.New("failed to create group") // ErrDeleteGroupMissing indicates in delete operation that group doesnt exist. ErrDeleteGroupMissing = errors.New("group is not existing, already deleted") // ErrAssignUserToGroup indicates an error in assigning user to a group. ErrAssignUserToGroup = errors.New("failed assigning user to a group") )
Functions ¶
This section is empty.
Types ¶
type Group ¶
type Group struct { ID string Name string OwnerID string ParentID string Description string Metadata map[string]interface{} }
Group of users
type GroupPage ¶
type GroupPage struct { PageMetadata Groups []Group }
type GroupRepository ¶
type GroupRepository interface { // Save persists the group. Save(ctx context.Context, g Group) (Group, error) // Update updates the group data. Update(ctx context.Context, g Group) error // Delete deletes group for given id. Delete(ctx context.Context, id string) error // RetrieveByID retrieves group by its unique identifier. RetrieveByID(ctx context.Context, id string) (Group, error) // RetrieveByName retrieves group by name RetrieveByName(ctx context.Context, name string) (Group, error) // RetrieveAllWithAncestors retrieves all groups if groupID == "", if groupID is specified returns children groups RetrieveAllWithAncestors(ctx context.Context, groupID string, offset, limit uint64, gm Metadata) (GroupPage, error) // Memberships retrieves all groups that user belongs to Memberships(ctx context.Context, userID string, offset, limit uint64, gm Metadata) (GroupPage, error) // Assign adds user to group. Assign(ctx context.Context, userID, groupID string) error // Unassign removes user from group Unassign(ctx context.Context, userID, groupID string) error }
GroupRepository specifies an group persistence API.
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 Metadata ¶
type Metadata map[string]interface{}
Metadata to be used for mainflux thing or channel for customized describing of particular thing or channel.
type PageMetadata ¶
PageMetadata contains page metadata that helps navigation.
type Service ¶
type Service interface { // Register creates new user account. In case of the failed registration, a // non-nil error value is returned. Register(ctx context.Context, user User) (string, error) // Login authenticates the user given its credentials. Successful // authentication generates new access token. Failed invocations are // identified by the non-nil error values in the response. Login(ctx context.Context, user User) (string, error) // User authenticated user info for the given token. User(ctx context.Context, token string) (User, error) // UpdateUser updates the user metadata. UpdateUser(ctx context.Context, token string, user User) error // GenerateResetToken email where mail will be sent. // host is used for generating reset link. GenerateResetToken(ctx context.Context, email, host string) error // ChangePassword change users password for authenticated user. ChangePassword(ctx context.Context, authToken, password, oldPassword string) error // ResetPassword change users password in reset flow. // token can be authentication token or password reset token. ResetPassword(ctx context.Context, resetToken, password string) error //SendPasswordReset sends reset password link to email. SendPasswordReset(ctx context.Context, host, email, token string) error // CreateGroup creates new user group. CreateGroup(ctx context.Context, token string, group Group) (Group, error) // UpdateGroup updates the group identified by the provided ID. UpdateGroup(ctx context.Context, token string, group Group) error // Group retrieves data about the group identified by ID. Group(ctx context.Context, token, id string) (Group, error) // ListGroups retrieves groups that are children to group identified by parenID // if parentID is empty all groups are listed. Groups(ctx context.Context, token, parentID string, offset, limit uint64, meta Metadata) (GroupPage, error) // Members retrieves users that are assigned to a group identified by groupID. Members(ctx context.Context, token, groupID string, offset, limit uint64, meta Metadata) (UserPage, error) // Memberships retrieves groups that user identified with userID belongs to. Memberships(ctx context.Context, token, groupID string, offset, limit uint64, meta Metadata) (GroupPage, error) // RemoveGroup removes the group identified with the provided ID. RemoveGroup(ctx context.Context, token, id string) error // Assign adds user with userID into the group identified by groupID. Assign(ctx context.Context, token, userID, groupID string) error // Unassign removes user with userID from group identified by groupID. Unassign(ctx context.Context, token, userID, groupID string) error }
Service specifies an API that must be fullfiled by the domain service implementation, and all of its decorators (e.g. logging & metrics).
func New ¶
func New(users UserRepository, groups GroupRepository, hasher Hasher, auth mainflux.AuthNServiceClient, m Emailer) Service
New instantiates the users service implementation
type User ¶
type User struct { ID string Email string Password string OwnerID string Owner *User Groups []Group Metadata Metadata }
User represents a Mainflux user account. Each user is identified given its email and password.
type UserPage ¶
type UserPage struct { PageMetadata Users []User }
type UserRepository ¶
type UserRepository interface { // Save persists the user account. A non-nil error is returned to indicate // operation failure. Save(ctx context.Context, u User) (string, error) // Update updates the user metadata. UpdateUser(ctx context.Context, u User) error // RetrieveByEmail retrieves user by its unique identifier (i.e. email). RetrieveByEmail(ctx context.Context, email string) (User, error) // RetrieveByID retrieves user by its unique identifier ID. RetrieveByID(ctx context.Context, id string) (User, error) // UpdatePassword updates password for user with given email UpdatePassword(ctx context.Context, email, password string) error // Members retrieves all users that belong to a group Members(ctx context.Context, groupID string, offset, limit uint64, um Metadata) (UserPage, error) }
UserRepository specifies an account persistence API.
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. |
http
Package http contains implementation of users service HTTP API.
|
Package http contains implementation of users service HTTP API. |
Package bcrypt provides a hasher implementation utilizing bcrypt.
|
Package bcrypt provides a hasher implementation utilizing bcrypt. |
Package postgres contains repository implementations using PostgreSQL as the underlying database.
|
Package postgres contains repository implementations using PostgreSQL as the underlying database. |
Package tracing contains middlewares that will add spans to existing traces.
|
Package tracing contains middlewares that will add spans to existing traces. |
Click to show internal directories.
Click to hide internal directories.