Documentation ¶
Index ¶
- Variables
- type ContextKey
- type Email
- type EmailEssential
- type EmailMetadata
- type Essential
- type Manager
- func (m *Manager) AccessPolicyManager() *accesspolicy.Manager
- func (m *Manager) CheckAvailability(ctx context.Context, username string, email string) error
- func (m *Manager) ConfirmEmail(ctx context.Context, addr string) (err error)
- func (m *Manager) CreateEmail(ctx context.Context, fn func(ctx context.Context) (NewEmailObject, error)) (email Email, err error)
- func (m *Manager) CreatePhone(ctx context.Context, fn func(ctx context.Context) (NewPhoneObject, error)) (phone Phone, err error)
- func (m *Manager) CreateProfile(ctx context.Context, fn func(ctx context.Context) (NewProfileObject, error)) (profile Profile, err error)
- func (m *Manager) CreateUser(ctx context.Context, fn func(ctx context.Context) (NewUserObject, error)) (u User, err error)
- func (m *Manager) DeleteEmailByAddr(ctx context.Context, userID uuid.UUID, addr string) (err error)
- func (m *Manager) DeletePhoneByNumber(ctx context.Context, userID uuid.UUID, number string) (phone Phone, err error)
- func (m *Manager) DeleteProfileByUserID(ctx context.Context, userID uuid.UUID) (err error)
- func (m *Manager) DeleteUserByID(ctx context.Context, id uuid.UUID, isHard bool) (u User, err error)
- func (m *Manager) EmailByAddr(ctx context.Context, addr string) (email Email, err error)
- func (m *Manager) GetProfileByID(ctx context.Context, id uuid.UUID) (profile Profile, err error)
- func (m *Manager) GroupManager() *group.Manager
- func (m *Manager) Logger() *zap.Logger
- func (m *Manager) PasswordManager() password.Manager
- func (m *Manager) PrimaryEmailByUserID(ctx context.Context, userID uuid.UUID) (email Email, err error)
- func (m *Manager) PrimaryPhoneByUserID(ctx context.Context, userID uuid.UUID) (phone Phone, err error)
- func (m *Manager) SetAccessPolicyManager(apm *accesspolicy.Manager) error
- func (m *Manager) SetGroupManager(gm *group.Manager) error
- func (m *Manager) SetLogger(logger *zap.Logger) error
- func (m *Manager) SetPassword(ctx context.Context, userID uuid.UUID, p password.Password) (err error)
- func (m *Manager) SetPasswordManager(pm password.Manager) error
- func (m *Manager) SetTokenManager(tm *token.Manager) error
- func (m *Manager) Store() (Store, error)
- func (m *Manager) SuspendUser(ctx context.Context, userID uuid.UUID, reason string, expireAt time.Time) (err error)
- func (m *Manager) TokenManager() *token.Manager
- func (m *Manager) UpdateEmail(ctx context.Context, addr string, ...) (email Email, essentialChangelog diff.Changelog, err error)
- func (m *Manager) UpdatePhone(ctx context.Context, number string, ...) (phone Phone, essentialChangelog diff.Changelog, err error)
- func (m *Manager) UpdateProfile(ctx context.Context, id uuid.UUID, ...) (profile Profile, essentialChangelog diff.Changelog, err error)
- func (m *Manager) UpdateUser(ctx context.Context, id uuid.UUID, ...) (u User, essentialChangelog diff.Changelog, err error)
- func (m *Manager) UserByEmailAddr(ctx context.Context, addr string) (u User, err error)
- func (m *Manager) UserByID(ctx context.Context, id uuid.UUID) (u User, err error)
- func (m *Manager) UserByUsername(ctx context.Context, username string) (u User, err error)
- func (m *Manager) Validate() error
- type Metadata
- type NewEmailObject
- type NewPhoneObject
- type NewProfileObject
- type NewUserObject
- type Phone
- type PhoneEssential
- type PhoneMetadata
- type PostgreSQLStore
- func (s *PostgreSQLStore) DeleteEmailByAddr(ctx context.Context, userID uuid.UUID, addr string) (err error)
- func (s *PostgreSQLStore) DeletePhoneByNumber(ctx context.Context, userID uuid.UUID, number string) (err error)
- func (s *PostgreSQLStore) DeleteProfileByUserID(ctx context.Context, userID uuid.UUID) (err error)
- func (s *PostgreSQLStore) DeleteUserByID(ctx context.Context, id uuid.UUID) (err error)
- func (s *PostgreSQLStore) FetchEmailByAddr(ctx context.Context, addr string) (e Email, err error)
- func (s *PostgreSQLStore) FetchEmailsByUserID(ctx context.Context, userID uuid.UUID) ([]Email, error)
- func (s *PostgreSQLStore) FetchPhoneByNumber(ctx context.Context, number string) (e Phone, err error)
- func (s *PostgreSQLStore) FetchPhonesByUserID(ctx context.Context, userID uuid.UUID) ([]Phone, error)
- func (s *PostgreSQLStore) FetchPrimaryEmailByUserID(ctx context.Context, userID uuid.UUID) (e Email, err error)
- func (s *PostgreSQLStore) FetchPrimaryPhoneByUserID(ctx context.Context, userID uuid.UUID) (e Phone, err error)
- func (s *PostgreSQLStore) FetchProfileByUserID(ctx context.Context, userID uuid.UUID) (profile Profile, err error)
- func (s *PostgreSQLStore) FetchUserByEmailAddr(ctx context.Context, addr string) (u User, err error)
- func (s *PostgreSQLStore) FetchUserByID(ctx context.Context, id uuid.UUID) (u User, err error)
- func (s *PostgreSQLStore) FetchUserByPhoneNumber(ctx context.Context, number string) (u User, err error)
- func (s *PostgreSQLStore) FetchUserByUsername(ctx context.Context, username string) (u User, err error)
- func (s *PostgreSQLStore) UpsertEmail(ctx context.Context, e Email) (_ Email, err error)
- func (s *PostgreSQLStore) UpsertPhone(ctx context.Context, p Phone) (_ Phone, err error)
- func (s *PostgreSQLStore) UpsertProfile(ctx context.Context, p Profile) (_ Profile, err error)
- func (s *PostgreSQLStore) UpsertUser(ctx context.Context, u User) (_ User, err error)
- type Profile
- type ProfileEssential
- type ProfileMetadata
- type Store
- type User
Constants ¶
This section is empty.
Variables ¶
var ( ErrZeroUserID = errors.New("user id is zero") ErrNoInputData = errors.New("no input data") ErrNilManager = errors.New("user manager is nil") ErrUserExists = errors.New("user already exists") ErrNilUser = errors.New("user is nil") ErrNilUserStore = errors.New("user store is nil") ErrUsernameTaken = errors.New("username is already taken") ErrEmptyEmailAddr = errors.New("empty email address") ErrDuplicateEmailAddr = errors.New("duplicate email address") ErrEmptyPhoneNumber = errors.New("empty phone number") ErrDuplicatePhoneNumber = errors.New("duplicate phone number") ErrEmailTaken = errors.New("email is already taken") ErrDuplicatePhone = errors.New("duplicate phone") ErrPhoneNotFound = errors.New("phone not found") ErrUserNotFound = errors.New("user not found") ErrEmailNotFound = errors.New("email not found") ErrUnknownUser = errors.New("unknown user") ErrInsufficientDataToHashKey = errors.New("insufficient data to hash a key") ErrUserAlreadyConfirmed = errors.New("user is already confirmed") ErrNilPasswordManager = errors.New("password manager is nil") ErrUserPasswordNotEligible = errors.New("user is not eligible for password assignment") ErrDuplicateProfile = errors.New("duplicate profile") ErrProfileNotFound = errors.New("profile not found") ErrNoParentPolicy = errors.New("no parent accesspolicy policy") ErrNoPolicyBackup = errors.New("no policy backup") ErrNoParentGroup = errors.New("no parent group") ErrZeroGroupID = errors.New("role group id is zero") ErrZeroRoleID = errors.New("role id is zero") ErrZeroAssignorID = errors.New("assignor id is zero") ErrZeroAssigneeID = errors.New("assignee id is zero") ErrNothingChanged = errors.New("nothing has changed") ErrZeroID = errors.New("id is zero") ErrNonZeroID = errors.New("id is non-zero") ErrInvalidSuspensionExpirationTime = errors.New("suspension expiration time is invalid") ErrUserAlreadySuspended = errors.New("user is already suspended") )
errors
Functions ¶
This section is empty.
Types ¶
type ContextKey ¶
type ContextKey uint16
const ( CKUserManager ContextKey = iota CKUser CKGroupManager CKAccessPolicyManager )
type Email ¶
type Email struct { UserID uuid.UUID `db:"user_id" json:"user_id"` EmailEssential EmailMetadata }
Email represents certain emails which are custom and are handled by the customer
func (*Email) ApplyChangelog ¶
ApplyChangelog applies changes described by a diff.Diff()'s changelog NOTE: doing a manual update to avoid using reflection
type EmailEssential ¶
type EmailEssential struct { Addr string `db:"addr" json:"addr"` IsPrimary bool `db:"is_primary" json:"is_primary"` }
EmailEssential represents an essential part of the primary object
type EmailMetadata ¶
type EmailMetadata struct { CreatedAt time.Time `db:"created_at" json:"created_at"` ConfirmedAt time.Time `db:"confirmed_at" json:"confirmed_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"` // contains filtered or unexported fields }
EmailMetadata contains generic metadata of the primary object
type Essential ¶
type Essential struct { Username string `db:"username" json:"username"` DisplayName string `db:"display_name" json:"display_name"` }
Essential represents an essential part of the primary object
type Manager ¶
userManager handles business logic of its underlying objects TODO: consider naming first release `Lidia`
func ManagerForTesting ¶
ManagerForTesting returns a fully initialized user manager for testing
func NewManager ¶
NewManager returns a new user manager instance also initializing by loading necessary data from a given store
func (*Manager) AccessPolicyManager ¶
func (m *Manager) AccessPolicyManager() *accesspolicy.Manager
func (*Manager) CheckAvailability ¶
CheckAvailability tests whether someone with such username or email is already registered
func (*Manager) ConfirmEmail ¶
ConfirmEmail this function is used only when user's email is confirmed
func (*Manager) CreateEmail ¶
func (m *Manager) CreateEmail(ctx context.Context, fn func(ctx context.Context) (NewEmailObject, error)) (email Email, err error)
UpsertEmail creates a new email
func (*Manager) CreatePhone ¶
func (m *Manager) CreatePhone(ctx context.Context, fn func(ctx context.Context) (NewPhoneObject, error)) (phone Phone, err error)
CreatePhone creates a new phone
func (*Manager) CreateProfile ¶
func (m *Manager) CreateProfile(ctx context.Context, fn func(ctx context.Context) (NewProfileObject, error)) (profile Profile, err error)
CreateProfile creates a new profile
func (*Manager) CreateUser ¶
func (m *Manager) CreateUser(ctx context.Context, fn func(ctx context.Context) (NewUserObject, error)) (u User, err error)
CreateUser creates a new user
func (*Manager) DeleteEmailByAddr ¶
DeleteEmailByAddr deletes an object and returns an object, which is an updated object if it's soft deleted, or nil otherwise
func (*Manager) DeletePhoneByNumber ¶
func (m *Manager) DeletePhoneByNumber(ctx context.Context, userID uuid.UUID, number string) (phone Phone, err error)
DeletePhoneByNumber deletes an object and returns an object, which is an updated object if it's soft deleted, or nil otherwise
func (*Manager) DeleteProfileByUserID ¶
DeleteProfileByUserID deletes an object and returns an object, which is an updated object if it's soft deleted, or nil otherwise
func (*Manager) DeleteUserByID ¶
func (m *Manager) DeleteUserByID(ctx context.Context, id uuid.UUID, isHard bool) (u User, err error)
DeleteUserByID deletes an object and returns an object, which is an updated object if it's soft deleted, or nil otherwise
func (*Manager) EmailByAddr ¶
EmailByAddr obtains an email by a given address
func (*Manager) GetProfileByID ¶
GetProfileByID returns a profile if found by ObjectID
func (*Manager) GroupManager ¶
func (*Manager) Logger ¶
Logger returns primary logger if is set, otherwise initializing and returning a new default emergency logger NOTE: will panic if it finally fails to obtain a logger
func (*Manager) PasswordManager ¶
func (*Manager) PrimaryEmailByUserID ¶
func (m *Manager) PrimaryEmailByUserID(ctx context.Context, userID uuid.UUID) (email Email, err error)
PrimaryEmailByUserID obtains the primary email by user id
func (*Manager) PrimaryPhoneByUserID ¶
func (m *Manager) PrimaryPhoneByUserID(ctx context.Context, userID uuid.UUID) (phone Phone, err error)
PrimaryPhoneByUserID obtains the primary phone by user id
func (*Manager) SetAccessPolicyManager ¶
func (m *Manager) SetAccessPolicyManager(apm *accesspolicy.Manager) error
SetAccessPolicyManager assigns accesspolicy policy manager
func (*Manager) SetGroupManager ¶
SetGroupManager assigns a group manager
func (*Manager) SetPassword ¶
func (m *Manager) SetPassword(ctx context.Context, userID uuid.UUID, p password.Password) (err error)
SetPassword sets a new password for the user
func (*Manager) SetPasswordManager ¶
SetPasswordManager assigns a password manager for this container
func (*Manager) SetTokenManager ¶
SetTokenManager assigns a token manager
func (*Manager) SuspendUser ¶
func (m *Manager) SuspendUser( ctx context.Context, userID uuid.UUID, reason string, expireAt time.Time, ) (err error)
SuspendUser suspends user by ID with a reason and expiration time
func (*Manager) TokenManager ¶
func (*Manager) UpdateEmail ¶
func (m *Manager) UpdateEmail(ctx context.Context, addr string, fn func(ctx context.Context, email Email) (_ Email, err error)) (email Email, essentialChangelog diff.Changelog, err error)
UpdateEmail updates an existing object NOTE: be very cautious about how you deal with metadata inside the user function
func (*Manager) UpdatePhone ¶
func (m *Manager) UpdatePhone(ctx context.Context, number string, fn func(ctx context.Context, phone Phone) (_ Phone, err error)) (phone Phone, essentialChangelog diff.Changelog, err error)
UpdatePhone updates an existing object NOTE: be very cautious about how you deal with metadata inside the user function
func (*Manager) UpdateProfile ¶
func (m *Manager) UpdateProfile(ctx context.Context, id uuid.UUID, fn func(context.Context, Profile) (Profile, error)) (profile Profile, essentialChangelog diff.Changelog, err error)
UpdateProfile updates an existing object NOTE: be very cautious about how you deal with metadata inside the user function
func (*Manager) UpdateUser ¶
func (m *Manager) UpdateUser(ctx context.Context, id uuid.UUID, fn func(ctx context.Context, u User) (_ User, err error)) (u User, essentialChangelog diff.Changelog, err error)
UpdateUser updates an existing object NOTE: be very cautious about how you deal with metadata inside the user function
func (*Manager) UserByEmailAddr ¶
UserByEmailAddr returns a user if found by username
func (*Manager) UserByUsername ¶
UserByUsername returns a user if found by username
type Metadata ¶
type Metadata struct { Checksum uint64 `db:"checksum" json:"checksum"` // timestamps CreatedAt time.Time `db:"created_at" json:"created_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"` ConfirmedAt time.Time `db:"confirmed_at" json:"confirmed_at"` DeletedAt time.Time `db:"deleted_at" json:"deleted_at"` // the most recent authentication information LastLoginAt time.Time `db:"last_login_at" json:"last_login_at"` LastLoginIP net.IP `db:"last_login_ip" json:"last_login_ip"` LastLoginFailedAt time.Time `db:"last_login_failed_at" json:"last_login_failed_at"` LastLoginFailedIP net.IP `db:"last_login_failed_ip" json:"last_login_failed_ip"` LastLoginAttempts uint8 `db:"last_login_attempts" json:"last_login_attempts"` // account suspension IsSuspended bool `db:"is_suspended" json:"is_suspended"` SuspendedAt time.Time `db:"suspended_at" json:"suspended_at"` SuspensionExpiresAt time.Time `db:"suspension_expires_at" json:"suspension_expires_at"` SuspensionReason string `db:"suspension_reason" json:"suspension_reason"` }
TODO: solve net.IPAddr field problem
type NewEmailObject ¶
type NewEmailObject struct { EmailEssential UserID uuid.UUID IsConfirmed bool }
EmailNewObject contains fields sufficient to create a new object
type NewPhoneObject ¶
type NewPhoneObject struct { PhoneEssential UserID uuid.UUID IsConfirmed bool }
NewPhoneObject contains fields sufficient to create a new object
type NewProfileObject ¶
type NewProfileObject struct { ProfileEssential UserID uuid.UUID `db:"user_id" json:"user_id"` }
NewProfileObject contains fields sufficient to create a new object
type NewUserObject ¶
type NewUserObject struct { Essential ProfileEssential EmailAddr string `json:"email_addr"` PhoneNumber string `json:"phone_number"` Password []byte `json:"password"` }
UserNewObject contains fields sufficient to create a new object
type Phone ¶
type Phone struct { UserID uuid.UUID `db:"user_id" json:"user_id"` PhoneEssential PhoneMetadata }
Phone represents certain emails which are custom and are handled by the customer
func (*Phone) ApplyChangelog ¶
ApplyChangelog applies changes described by a diff.Diff()'s changelog NOTE: doing a manual update to avoid using reflection
type PhoneEssential ¶
type PhoneEssential struct { Number string `db:"number" json:"number"` IsPrimary bool `db:"is_primary" json:"is_primary"` }
PhoneEssential represents an essential part of the primary object
type PhoneMetadata ¶
type PhoneMetadata struct { CreatedAt time.Time `db:"created_at" json:"created_at"` ConfirmedAt time.Time `db:"confirmed_at" json:"confirmed_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"` // contains filtered or unexported fields }
PhoneMetadata contains generic metadata of the primary object
type PostgreSQLStore ¶
type PostgreSQLStore struct {
// contains filtered or unexported fields
}
func (*PostgreSQLStore) DeleteEmailByAddr ¶
func (*PostgreSQLStore) DeletePhoneByNumber ¶
func (*PostgreSQLStore) DeleteProfileByUserID ¶
func (*PostgreSQLStore) DeleteUserByID ¶
func (*PostgreSQLStore) FetchEmailByAddr ¶
func (*PostgreSQLStore) FetchEmailsByUserID ¶
func (*PostgreSQLStore) FetchPhoneByNumber ¶
func (*PostgreSQLStore) FetchPhonesByUserID ¶
func (*PostgreSQLStore) FetchPrimaryEmailByUserID ¶
func (*PostgreSQLStore) FetchPrimaryPhoneByUserID ¶
func (*PostgreSQLStore) FetchProfileByUserID ¶
func (*PostgreSQLStore) FetchUserByEmailAddr ¶
func (*PostgreSQLStore) FetchUserByID ¶
func (*PostgreSQLStore) FetchUserByPhoneNumber ¶
func (*PostgreSQLStore) FetchUserByUsername ¶
func (*PostgreSQLStore) UpsertEmail ¶
UpsertEmail creates a new entry in the storage backend
func (*PostgreSQLStore) UpsertPhone ¶
func (*PostgreSQLStore) UpsertProfile ¶
func (*PostgreSQLStore) UpsertUser ¶
CreateUser creates a new entry in the storage backend
type Profile ¶
type Profile struct { UserID uuid.UUID `db:"user_id" json:"-"` ProfileEssential ProfileMetadata }
Profile represents certain profiles which are custom and are handled by the customer
func (*Profile) ApplyChangelog ¶
ApplyChangelog applies changes described by a diff.Diff()'s changelog NOTE: doing a manual update to avoid using reflection
type ProfileEssential ¶
type ProfileEssential struct { Firstname string `db:"firstname" json:"firstname"` Lastname string `db:"lastname" json:"lastname"` Middlename string `db:"middlename" json:"middlename"` }
ProfileEssential represents an essential part of the primary object
type ProfileMetadata ¶
type ProfileMetadata struct { Checksum uint64 `db:"checksum" json:"checksum"` CreatedAt time.Time `db:"created_at" json:"created_at"` UpdatedAt time.Time `db:"updated_at" json:"updated_at"` // contains filtered or unexported fields }
ProfileMetadata contains generic metadata of the primary object
type Store ¶
type Store interface { // user UpsertUser(ctx context.Context, u User) (_ User, err error) FetchUserByID(ctx context.Context, id uuid.UUID) (u User, err error) FetchUserByUsername(ctx context.Context, username string) (u User, err error) FetchUserByEmailAddr(ctx context.Context, addr string) (u User, err error) FetchUserByPhoneNumber(ctx context.Context, number string) (u User, err error) DeleteUserByID(ctx context.Context, id uuid.UUID) (err error) // emails UpsertEmail(ctx context.Context, e Email) (_ Email, err error) FetchPrimaryEmailByUserID(ctx context.Context, userID uuid.UUID) (e Email, err error) FetchEmailByAddr(ctx context.Context, addr string) (e Email, err error) FetchEmailsByUserID(ctx context.Context, userID uuid.UUID) (es []Email, err error) DeleteEmailByAddr(ctx context.Context, userID uuid.UUID, addr string) (err error) // phones UpsertPhone(ctx context.Context, p Phone) (_ Phone, err error) FetchPrimaryPhoneByUserID(ctx context.Context, userID uuid.UUID) (p Phone, err error) FetchPhoneByNumber(ctx context.Context, number string) (p Phone, err error) FetchPhonesByUserID(ctx context.Context, userID uuid.UUID) (ps []Phone, err error) DeletePhoneByNumber(ctx context.Context, userID uuid.UUID, number string) (err error) // profile UpsertProfile(ctx context.Context, p Profile) (_ Profile, err error) FetchProfileByUserID(ctx context.Context, userID uuid.UUID) (p Profile, err error) DeleteProfileByUserID(ctx context.Context, userID uuid.UUID) (err error) }
Store represents a user storage backend contract
type User ¶
type User struct { ID uuid.UUID `db:"id" json:"id"` Essential Metadata // contains filtered or unexported fields }
User represents certain users which are custom and are handled by the customer
func CreateTestUser ¶
func (*User) ApplyChangelog ¶
ApplyChangelog applies changes described by a diff.Diff()'s changelog NOTE: doing a manual update to avoid using reflection
Source Files ¶
- email.go
- email_manager.go
- email_store_mysql.go
- email_store_postgres.go
- error.go
- manager.go
- phone.go
- phone_manager.go
- phone_store_mysql.go
- phone_store_postgres.go
- profile.go
- profile_manager.go
- profile_store_mysql.go
- profile_store_postgres.go
- store.go
- testing.go
- user.go
- user_manager.go
- user_store_mysql.go
- user_store_postgres.go