Versions in this module Expand all Collapse all v0 v0.0.4 Jul 9, 2022 Changes in this version + const Admin + const AdminEmailKey + const AdminPasswordKey + const AdminUsernameKey + const ConfirmPurpose + const ConnName + const EmailName + const InternalLoginProvider + const InternalRememberTokenName + const JobTypeUserMigration + const PhoneName + const RecoverChangePasswordPurpose + const RecoverPurpose + const TwoStepName + var ErrWriterNotFound = errors.New("writer not found") + var ProviderSet = wire.NewSet(NewUserManager, NewSignInManager, NewUserValidator, NewRoleManager, ...) + func FromEnableUserTenantContext(ctx context.Context) bool + func GenerateOtp() (string, error) + func NewEnableUserTenantsContext(ctx context.Context, enable ...bool) context.Context + func NewUserMigrationTask(msg *v1.TenantCreatedEvent) (*asynq.Task, error) + func ProfileBlob(ctx context.Context, factory blob.Factory) blob.Blob + type DefaultEmailSender struct + func (d *DefaultEmailSender) SendForgetPassword(ctx context.Context, email, token string) error + func (d *DefaultEmailSender) SendInviteTenant(ctx context.Context, email, token string) error + type EmailSender interface + SendForgetPassword func(ctx context.Context, email, token string) error + SendInviteTenant func(ctx context.Context, email, token string) error + func NewEmailSender(emailer email.LazyClient, cfg *kconf.Data) EmailSender + type EmailTokenProvider struct + func NewEmailTokenProvider(r cache.CacheInterface[string]) *EmailTokenProvider + func (e *EmailTokenProvider) CanGenerate(ctx context.Context, user *User) error + func (e *EmailTokenProvider) Generate(ctx context.Context, purpose TokenPurpose, user *User, duration time.Duration) (string, error) + func (e *EmailTokenProvider) Name() string + func (e *EmailTokenProvider) Validate(ctx context.Context, purpose TokenPurpose, token string, user *User) (bool, error) + type LookupNormalizer interface + Email func(email string) (string, error) + Name func(name string) (string, error) + Phone func(phone string) (string, error) + func NewLookupNormalizer() LookupNormalizer + type PasswordHasher interface + HashPassword func(ctx context.Context, user *User, password string) (hash string, err error) + VerifyHashedPassword func(ctx context.Context, user *User, hashedPassword string, ...) PasswordVerificationResult + func NewPasswordHasher() PasswordHasher + type PasswordValidator interface + Validate func(ctx context.Context, password string) error + func NewPasswordValidator(c *conf.UserConf) PasswordValidator + type PasswordVerificationResult int32 + const PasswordVerificationFail + const PasswordVerificationSuccess + const PasswordVerificationSuccessRehashNeeded + type PermissionSeeder struct + func NewPermissionSeeder(permission authz.PermissionManagementService, checker authz.PermissionChecker, ...) *PermissionSeeder + func (p *PermissionSeeder) Seed(ctx context.Context, sCtx *seed.Context) error + type PhoneTokenProvider struct + func NewPhoneTokenProvider(r cache.CacheInterface[string]) *PhoneTokenProvider + func (p *PhoneTokenProvider) CanGenerate(ctx context.Context, user *User) error + func (p *PhoneTokenProvider) Generate(ctx context.Context, purpose TokenPurpose, user *User, duration time.Duration) (string, error) + func (p *PhoneTokenProvider) Name() string + func (p *PhoneTokenProvider) Validate(ctx context.Context, purpose TokenPurpose, token string, user *User) (bool, error) + type RefreshToken struct + Expires *time.Time + Ip string + Token string + Used bool + UserAgent string + UserId uuid.UUID + func NewRefreshToken(userId uuid.UUID, duration time.Duration, userAgent string, ip string) *RefreshToken + func (r *RefreshToken) Valid() bool + type RefreshTokenRepo interface + Create func(ctx context.Context, t *RefreshToken) (err error) + Find func(ctx context.Context, token string, validOnly bool) (*RefreshToken, error) + Revoke func(ctx context.Context, token string, used bool) (err error) + type Role struct + IsPreserved bool + Name string + NormalizedName string + type RoleManager struct + func NewRoleManager(repo RoleRepo, lookupNormalizer LookupNormalizer) *RoleManager + func (r *RoleManager) Count(ctx context.Context, query *v12.ListRolesRequest) (total int64, filtered int64, err error) + func (r *RoleManager) Create(ctx context.Context, role *Role) error + func (r *RoleManager) Delete(ctx context.Context, id string) error + func (r *RoleManager) FindByName(ctx context.Context, name string) (*Role, error) + func (r *RoleManager) First(ctx context.Context, query *v12.ListRolesRequest) (*Role, error) + func (r *RoleManager) Get(ctx context.Context, id string) (*Role, error) + func (r *RoleManager) List(ctx context.Context, query *v12.ListRolesRequest) ([]*Role, error) + func (r *RoleManager) Update(ctx context.Context, id string, role *Role, p query.Select) error + type RoleRepo interface + FindByName func(ctx context.Context, name string) (*Role, error) + type RoleSeed struct + func NewRoleSeed(roleMgr *RoleManager, permission authz.PermissionManagementService) *RoleSeed + func (r *RoleSeed) Seed(ctx context.Context, sCtx *seed.Context) error + type SignInManager struct + func NewSignInManager(um *UserManager, securityCfg *conf.Security) *SignInManager + func (s *SignInManager) CheckCanSignIn(ctx context.Context, u *User) error + func (s *SignInManager) ExternalLoginSignInAsync(ctx context.Context, loginProvider, providerKey string, ...) error + func (s *SignInManager) ForgetTwoFactorClient(ctx context.Context) error + func (s *SignInManager) GetTwoFactorAuthenticationUser(ctx context.Context) (*User, error) + func (s *SignInManager) IsSignedIn(ctx context.Context) (bool, error) + func (s *SignInManager) IsTwoFactorClientRemembered(ctx context.Context, u *User) (bool, error) + func (s *SignInManager) PasswordSignIn(ctx context.Context, u *User, pwd string, isPersistent bool, ...) error + func (s *SignInManager) PasswordSignInWithEmail(ctx context.Context, email, pwd string, isPersistent bool, ...) (error, string) + func (s *SignInManager) PasswordSignInWithPhone(ctx context.Context, phone, pwd string, isPersistent bool, ...) (error, string) + func (s *SignInManager) PasswordSignInWithUsername(ctx context.Context, username, pwd string, isPersistent bool, ...) (error, string) + func (s *SignInManager) RememberTwoFactorClient(ctx context.Context, u *User) error + func (s *SignInManager) SignIn(ctx context.Context, u *User, isPersistent bool) error + func (s *SignInManager) SignOut(ctx context.Context) error + func (s *SignInManager) TwoFactorAuthenticatorSignIn(ctx context.Context, code string, isPersistent, rememberClient bool) error + func (s *SignInManager) TwoFactorSignIn(ctx context.Context, provider, code string, isPersistent, rememberClient bool) error + func (s *SignInManager) ValidateSecurityStamp(ctx context.Context, u *User, securityStamp string) + type TenantSeedEventHandler event.ConsumerHandler + func NewTenantSeedEventHandler(client *asynq.Client) TenantSeedEventHandler + type TokenPurpose string + type TwoStepTokenProvider struct + func NewTwoStepTokenProvider(creator func() T, proxy cache.CacheInterface[string]) *TwoStepTokenProvider[T] + func (p *TwoStepTokenProvider[T]) Generate(ctx context.Context, purpose TokenPurpose, payload T, duration time.Duration) (string, error) + func (p *TwoStepTokenProvider[T]) Name() string + func (p *TwoStepTokenProvider[T]) Retrieve(ctx context.Context, purpose TokenPurpose, token string) (T, error) + type UpdateUserSetting struct + Delete bool + Key string + Value *data.Value + type User struct + AccessFailedCount int + Avatar *string + Birthday *time.Time + CreatedTenant *string + DeletedAt gorm2.DeletedAt + Email *string + EmailConfirmed bool + Extra data.JSONMap + FirstName *string + Gender *string + LastLoginAttempt *time.Time + LastName *string + Location *string + LockoutEndDateUtc *time.Time + Name *string + NormalizedEmail *string + NormalizedUsername *string + Password *string + Phone *string + PhoneConfirmed bool + Roles []Role + Tags *string + Tenants []UserTenant + TwoFactorEnabled bool + Username *string + type UserAddress struct + Address data.AddressEntity + Metadata data.JSONMap + Phone string + Prefer bool + Usage string + UserId string + type UserAddressRepo interface + FindByUser func(ctx context.Context, userId string) ([]*UserAddress, error) + SetPrefer func(ctx context.Context, addr *UserAddress) error + type UserLogin struct + LoginProvider string + ProviderKey string + UserId uuid.UUID + type UserManager struct + func NewUserManager(cfg *conf.UserConf, userRepo UserRepo, pwdHasher PasswordHasher, ...) *UserManager + func (um *UserManager) AddToRole(ctx context.Context, user *User, role *Role) error + func (um *UserManager) ChangePassword(ctx context.Context, user *User, current string, newPwd string) error + func (um *UserManager) ChangePasswordByToken(ctx context.Context, token, newPwd string) error + func (um *UserManager) CheckDeleted(ctx context.Context, u *User) (bool, error) + func (um *UserManager) CheckLocked(ctx context.Context, u *User) (bool, error) + func (um *UserManager) CheckPassword(ctx context.Context, user *User, password string) error + func (um *UserManager) Count(ctx context.Context, query *v1.UserFilter) (total int64, filtered int64, err error) + func (um *UserManager) Create(ctx context.Context, u *User) (err error) + func (um *UserManager) CreateWithPassword(ctx context.Context, u *User, pwd string, validate bool) (err error) + func (um *UserManager) Delete(ctx context.Context, user *User) error + func (um *UserManager) FindByEmail(ctx context.Context, email string) (user *User, err error) + func (um *UserManager) FindByID(ctx context.Context, id string) (user *User, err error) + func (um *UserManager) FindByIdentity(ctx context.Context, identity string) (user *User, err error) + func (um *UserManager) FindByName(ctx context.Context, name string) (user *User, err error) + func (um *UserManager) FindByPhone(ctx context.Context, phone string) (user *User, err error) + func (um *UserManager) GenerateEmailForgetPasswordToken(ctx context.Context, user *User) (string, error) + func (um *UserManager) GenerateForgetPasswordToken(ctx context.Context, user *User) (string, error) + func (um *UserManager) GeneratePhoneForgetPasswordToken(ctx context.Context, user *User) (string, error) + func (um *UserManager) GenerateRememberToken(ctx context.Context, duration time.Duration, uid uuid.UUID) (string, error) + func (um *UserManager) GetRoles(ctx context.Context, user *User) ([]Role, error) + func (um *UserManager) IsInTenant(ctx context.Context, uid, tenantId string) (bool, error) + func (um *UserManager) JoinTenant(ctx context.Context, uid, tenantId string) error + func (um *UserManager) List(ctx context.Context, query *v1.ListUsersRequest) ([]*User, error) + func (um *UserManager) RefreshRememberToken(ctx context.Context, token string, duration time.Duration) (*User, string, error) + func (um *UserManager) RemoveFromRole(ctx context.Context, user *User, role *Role) error + func (um *UserManager) RemoveFromTenant(ctx context.Context, uid, tenantId string) error + func (um *UserManager) Update(ctx context.Context, user *User, p *fieldmaskpb.FieldMask) (err error) + func (um *UserManager) UpdatePassword(ctx context.Context, user *User, newPwd string) error + func (um *UserManager) UpdateRoles(ctx context.Context, user *User, roles []Role) error + func (um *UserManager) VerifyEmailForgetPasswordToken(ctx context.Context, email, token string) error + func (um *UserManager) VerifyPhoneForgetPasswordToken(ctx context.Context, phone, token string) error + type UserMigrationTaskHandler func(ctx context.Context, t *asynq.Task) error + func NewUserMigrationTaskHandler(seeder seed.Seeder, sender event.Producer) UserMigrationTaskHandler + type UserRepo interface + AddLogin func(ctx context.Context, user *User, userLogin *UserLogin) error + AddToRole func(ctx context.Context, user *User, role *Role) error + Count func(ctx context.Context, query *v1.UserFilter) (total int64, filtered int64, err error) + Create func(ctx context.Context, user *User) error + Delete func(ctx context.Context, user *User) error + FindByEmail func(ctx context.Context, email string) (*User, error) + FindByID func(ctx context.Context, id string) (*User, error) + FindByLogin func(ctx context.Context, loginProvider string, providerKey string) (*User, error) + FindByName func(ctx context.Context, name string) (*User, error) + FindByPhone func(ctx context.Context, phone string) (*User, error) + GetRoles func(ctx context.Context, user *User) ([]Role, error) + GetToken func(ctx context.Context, user *User, loginProvider string, name string) (*string, error) + List func(ctx context.Context, query *v1.ListUsersRequest) ([]*User, error) + ListLogin func(ctx context.Context, user *User) ([]*UserLogin, error) + RemoveFromRole func(ctx context.Context, user *User, role *Role) error + RemoveLogin func(ctx context.Context, user *User, loginProvider string, providerKey string) error + RemoveToken func(ctx context.Context, user *User, loginProvider string, name string) error + SetToken func(ctx context.Context, user *User, loginProvider string, name string, ...) error + Update func(ctx context.Context, user *User, p *fieldmaskpb.FieldMask) error + UpdateRoles func(ctx context.Context, user *User, roles []Role) error + type UserRole struct + RoleID uuid.UUID + UserID uuid.UUID + type UserSeed struct + func NewUserSeed(um *UserManager, rm *RoleManager) *UserSeed + func (u *UserSeed) Seed(ctx context.Context, sCtx *seed.Context) error + type UserSetting struct + Key string + UserId string + Value data.Value + type UserSettingRepo interface + FindByUser func(ctx context.Context, userId string, query *v1.GetSettingsRequest) ([]*UserSetting, error) + UpdateByUser func(ctx context.Context, userId string, updateBatch []UpdateUserSetting) error + type UserTenant struct + DeletedAt gg.DeletedAt + Extra data.JSONMap + JoinTime time.Time + Status UserTenantStatus + TenantId *string + UserId string + func (u *UserTenant) GetTenantId() string + func (u *UserTenant) SetTenantId(id string) *UserTenant + type UserTenantRepo interface + Get func(ctx context.Context, userId string, tenantId string) (*UserTenant, error) + IsIn func(ctx context.Context, userId string, tenantId string) (bool, error) + JoinTenant func(ctx context.Context, userId string, tenantId string, status UserTenantStatus) (*UserTenant, error) + RemoveFromTenant func(ctx context.Context, userId string, tenantId string) error + Update func(ctx context.Context, userTenant *UserTenant) error + type UserTenantStatus int32 + const Active + const Inactive + func (p UserTenantStatus) String() string + type UserToken struct + DeletedAt gorm2.DeletedAt + LoginProvider string + Name string + UserId uuid.UUID + Value string + type UserTokenProvider interface + CanGenerate func(ctx context.Context, user *User) error + Generate func(ctx context.Context, purpose TokenPurpose, user *User, duration time.Duration) (token string, err error) + Name func() string + Validate func(ctx context.Context, purpose TokenPurpose, token string, user *User) (bool, error) + type UserTokenRepo interface + Create func(ctx context.Context, userId, loginProvider, name, value string) (*UserToken, error) + DeleteByUserIdAndLoginProvider func(ctx context.Context, userId, loginProvider string) error + DeleteByUserIdAndLoginProviderAndName func(ctx context.Context, userId, loginProvider, name string) error + FindByUserIdAndLoginProvider func(ctx context.Context, userId, loginProvider string) ([]*UserToken, error) + FindByUserIdAndLoginProviderAndName func(ctx context.Context, userId, loginProvider, name string) (*UserToken, error) + type UserValidator interface + Validate func(ctx context.Context, um *UserManager, user *User) (err error) + func NewUserValidator() UserValidator