biz

package
v0.0.5-0...-8e55a6f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 55 Imported by: 3

README

Biz

Documentation

Index

Constants

View Source
const (
	Admin            = "admin"
	AdminUsernameKey = "admin_username"
	AdminEmailKey    = "admin_email"
	AdminPasswordKey = "admin_password"
	AdminUserId      = "admin_user_id"
)
View Source
const (
	InternalLoginProvider     string = "internal"
	InternalRememberTokenName string = "remember"
)
View Source
const (
	EmailName   = "email"
	PhoneName   = "phone"
	TwoStepName = "twostep"
	OtpName     = "otp"

	EmailLoginPurpose = "login_email"
	PhoneLoginPurpose = "login_phone"

	ConfirmPurpose               TokenPurpose = "confirm"
	RecoverPurpose               TokenPurpose = "recover"
	RecoverChangePasswordPurpose TokenPurpose = "recover_change_password"
)
View Source
const ConnName dal.ConnName = "user"
View Source
const UserAvatarPath = "user/avatar"

Variables

View Source
var (
	ErrWriterNotFound = errors.New("writer not found")
)
View Source
var File_user_private_biz_cache_proto protoreflect.FileDescriptor

ProviderSet is biz providers.

Functions

func GenerateOtp

func GenerateOtp() (string, error)

func NewUserRoleChangeEventHandler

func NewUserRoleChangeEventHandler(um *UserManager) event.ConsumerHandler

Types

type DefaultEmailSender

type DefaultEmailSender struct {
	// contains filtered or unexported fields
}

DefaultEmailSender TODO template?

func (*DefaultEmailSender) SendForgetPassword

func (d *DefaultEmailSender) SendForgetPassword(ctx context.Context, email, token string) error

func (*DefaultEmailSender) SendInviteTenant

func (d *DefaultEmailSender) SendInviteTenant(ctx context.Context, email, token string) error

func (*DefaultEmailSender) SendPasswordlessLogin

func (d *DefaultEmailSender) SendPasswordlessLogin(ctx context.Context, email, token string) error

type DefaultOtpTokenProvider

type DefaultOtpTokenProvider struct {
	// contains filtered or unexported fields
}

func (*DefaultOtpTokenProvider) GenerateOtp

func (p *DefaultOtpTokenProvider) GenerateOtp(ctx context.Context, purpose TokenPurpose, extraKey string, duration time.Duration) (string, error)

func (*DefaultOtpTokenProvider) VerifyOtp

func (p *DefaultOtpTokenProvider) VerifyOtp(ctx context.Context, purpose TokenPurpose, extraKey string, token string) (bool, error)

type EmailSender

type EmailSender interface {
	//SendForgetPassword send forget password token
	SendForgetPassword(ctx context.Context, email, token string) error
	//SendInviteTenant send invite people into tenant
	SendInviteTenant(ctx context.Context, email, token string) error
	SendPasswordlessLogin(ctx context.Context, email, token string) error
}

func NewEmailSender

func NewEmailSender(emailer email.Client, cfg *kconf.Data) EmailSender

type EmailTokenProvider

type EmailTokenProvider struct {
	// contains filtered or unexported fields
}

func NewEmailTokenProvider

func NewEmailTokenProvider(r cache.CacheInterface[string]) *EmailTokenProvider

func (*EmailTokenProvider) CanGenerate

func (e *EmailTokenProvider) CanGenerate(ctx context.Context, user *User) error

func (*EmailTokenProvider) Generate

func (e *EmailTokenProvider) Generate(ctx context.Context, purpose TokenPurpose, user *User, duration time.Duration) (string, error)

func (*EmailTokenProvider) Name

func (e *EmailTokenProvider) Name() string

func (*EmailTokenProvider) Validate

func (e *EmailTokenProvider) Validate(ctx context.Context, purpose TokenPurpose, token string, user *User) (bool, error)

type ForgetPasswordTwoStepTokenPayload

type ForgetPasswordTwoStepTokenPayload struct {
	UserId string `protobuf:"bytes,1,opt,name=user_id,json=userId,proto3" json:"user_id,omitempty"`
	// contains filtered or unexported fields
}

func (*ForgetPasswordTwoStepTokenPayload) Descriptor deprecated

func (*ForgetPasswordTwoStepTokenPayload) Descriptor() ([]byte, []int)

Deprecated: Use ForgetPasswordTwoStepTokenPayload.ProtoReflect.Descriptor instead.

func (*ForgetPasswordTwoStepTokenPayload) GetUserId

func (*ForgetPasswordTwoStepTokenPayload) ProtoMessage

func (*ForgetPasswordTwoStepTokenPayload) ProtoMessage()

func (*ForgetPasswordTwoStepTokenPayload) ProtoReflect

func (*ForgetPasswordTwoStepTokenPayload) Reset

func (*ForgetPasswordTwoStepTokenPayload) String

func (*ForgetPasswordTwoStepTokenPayload) Validate

Validate checks the field values on ForgetPasswordTwoStepTokenPayload with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*ForgetPasswordTwoStepTokenPayload) ValidateAll

func (m *ForgetPasswordTwoStepTokenPayload) ValidateAll() error

ValidateAll checks the field values on ForgetPasswordTwoStepTokenPayload with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in ForgetPasswordTwoStepTokenPayloadMultiError, or nil if none found.

type ForgetPasswordTwoStepTokenPayloadMultiError

type ForgetPasswordTwoStepTokenPayloadMultiError []error

ForgetPasswordTwoStepTokenPayloadMultiError is an error wrapping multiple validation errors returned by ForgetPasswordTwoStepTokenPayload.ValidateAll() if the designated constraints aren't met.

func (ForgetPasswordTwoStepTokenPayloadMultiError) AllErrors

AllErrors returns a list of validation violation errors.

func (ForgetPasswordTwoStepTokenPayloadMultiError) Error

Error returns a concatenation of all the error messages it wraps.

type ForgetPasswordTwoStepTokenPayloadValidationError

type ForgetPasswordTwoStepTokenPayloadValidationError struct {
	// contains filtered or unexported fields
}

ForgetPasswordTwoStepTokenPayloadValidationError is the validation error returned by ForgetPasswordTwoStepTokenPayload.Validate if the designated constraints aren't met.

func (ForgetPasswordTwoStepTokenPayloadValidationError) Cause

Cause function returns cause value.

func (ForgetPasswordTwoStepTokenPayloadValidationError) Error

Error satisfies the builtin error interface

func (ForgetPasswordTwoStepTokenPayloadValidationError) ErrorName

ErrorName returns error name.

func (ForgetPasswordTwoStepTokenPayloadValidationError) Field

Field function returns field value.

func (ForgetPasswordTwoStepTokenPayloadValidationError) Key

Key function returns key value.

func (ForgetPasswordTwoStepTokenPayloadValidationError) Reason

Reason function returns reason value.

type LookupNormalizer

type LookupNormalizer interface {
	// Name normalizer
	Name(ctx context.Context, name string) (string, error)
	// Email normalizer
	Email(ctx context.Context, email string) (string, error)
	// Phone normalizer
	Phone(ctx context.Context, phone string) (string, error)
}

func NewLookupNormalizer

func NewLookupNormalizer(cfg *conf.AppConfig) LookupNormalizer

type OtpTokenProvider

type OtpTokenProvider interface {
	GenerateOtp(ctx context.Context, purpose TokenPurpose, extraKey string, duration time.Duration) (string, error)
	VerifyOtp(ctx context.Context, purpose TokenPurpose, extraKey string, token string) (bool, error)
}

type PasswordHasher

type PasswordHasher interface {
	HashPassword(ctx context.Context, user *User, password string) (hash string, err error)
	VerifyHashedPassword(ctx context.Context, user *User, hashedPassword string, providedPassword string) PasswordVerificationResult
}

func NewPasswordHasher

func NewPasswordHasher() PasswordHasher

type PasswordValidator

type PasswordValidator interface {
	// Validate password
	Validate(ctx context.Context, password string) error
}

func NewPasswordValidator

func NewPasswordValidator(c *conf.UserConf) PasswordValidator

type PasswordVerificationResult

type PasswordVerificationResult int32
const (
	PasswordVerificationFail PasswordVerificationResult = iota
	PasswordVerificationSuccess
	PasswordVerificationSuccessRehashNeeded
)

type PermissionSeeder

type PermissionSeeder struct {
	// contains filtered or unexported fields
}

func (*PermissionSeeder) Seed

func (p *PermissionSeeder) Seed(ctx context.Context, sCtx *seed.Context) error

type PhoneTokenProvider

type PhoneTokenProvider struct {
	// contains filtered or unexported fields
}

func NewPhoneTokenProvider

func NewPhoneTokenProvider(r cache.CacheInterface[string]) *PhoneTokenProvider

func (*PhoneTokenProvider) CanGenerate

func (p *PhoneTokenProvider) CanGenerate(ctx context.Context, user *User) error

func (*PhoneTokenProvider) Generate

func (p *PhoneTokenProvider) Generate(ctx context.Context, purpose TokenPurpose, user *User, duration time.Duration) (string, error)

func (*PhoneTokenProvider) Name

func (p *PhoneTokenProvider) Name() string

func (*PhoneTokenProvider) Validate

func (p *PhoneTokenProvider) Validate(ctx context.Context, purpose TokenPurpose, token string, user *User) (bool, error)

type RefreshToken

type RefreshToken struct {
	Token     string    `gorm:"type:char(36);primaryKey"`
	UserId    uuid.UUID `gorm:"type:char(36);index" json:"user_id"`
	Expires   *time.Time
	Ip        string
	UserAgent string
	Used      bool
}

func NewRefreshToken

func NewRefreshToken(userId uuid.UUID, duration time.Duration, userAgent string, ip string) *RefreshToken

func (*RefreshToken) Valid

func (r *RefreshToken) Valid() bool

type RefreshTokenRepo

type RefreshTokenRepo interface {
	Create(ctx context.Context, t *RefreshToken) (err error)
	Find(ctx context.Context, token string, validOnly bool) (*RefreshToken, error)
	// Revoke refresh token
	Revoke(ctx context.Context, token string, used bool) (err error)
}

type Role

type Role struct {
	kitgorm.UIDBase
	concurrency.HasVersion `gorm:"type:char(36)"`
	kitgorm.AuditedModel
	TenantId       sgorm.HasTenant `gorm:"index:idx_tenant_role,unique"`
	Name           string          `json:"name" gorm:"size:200"`
	NormalizedName string          `gorm:"size:200;index:idx_tenant_role,unique" json:"normalized_name" `
	IsPreserved    bool            `json:"is_preserved"`
}

type RoleManager

type RoleManager struct {
	// contains filtered or unexported fields
}

func NewRoleManager

func NewRoleManager(repo RoleRepo, lookupNormalizer LookupNormalizer) *RoleManager

func (*RoleManager) Count

func (r *RoleManager) Count(ctx context.Context, query *v12.ListRolesRequest) (total int64, filtered int64, err error)

func (*RoleManager) Create

func (r *RoleManager) Create(ctx context.Context, role *Role) error

func (*RoleManager) Delete

func (r *RoleManager) Delete(ctx context.Context, id string) error

func (*RoleManager) FindByName

func (r *RoleManager) FindByName(ctx context.Context, name string) (*Role, error)

func (*RoleManager) First

func (r *RoleManager) First(ctx context.Context, query *v12.ListRolesRequest) (*Role, error)

func (*RoleManager) Get

func (r *RoleManager) Get(ctx context.Context, id string) (*Role, error)

func (*RoleManager) List

func (r *RoleManager) List(ctx context.Context, query *v12.ListRolesRequest) ([]*Role, error)

func (*RoleManager) Update

func (r *RoleManager) Update(ctx context.Context, id string, role *Role, p query.Select) error

type RoleRepo

type RoleRepo interface {
	data.Repo[Role, string, *v12.ListRolesRequest]
	FindByName(ctx context.Context, name string) (*Role, error)
}

RoleRepo crud role

type RoleSeed

type RoleSeed struct {
	// contains filtered or unexported fields
}

func NewRoleSeed

func NewRoleSeed(roleMgr *RoleManager, permission authz.PermissionManagementService) *RoleSeed

func (*RoleSeed) Seed

func (r *RoleSeed) Seed(ctx context.Context, _ *seed.Context) error

type SignInManager

type SignInManager struct {
	// contains filtered or unexported fields
}

func NewSignInManager

func NewSignInManager(um *UserManager, securityCfg *conf.Security) *SignInManager

func (*SignInManager) CheckCanSignIn

func (s *SignInManager) CheckCanSignIn(ctx context.Context, u *User) error

func (*SignInManager) ExternalLoginSignInAsync

func (s *SignInManager) ExternalLoginSignInAsync(ctx context.Context, loginProvider, providerKey string, isPersistent, bypassTwoFactor bool) error

func (*SignInManager) ForgetTwoFactorClient

func (s *SignInManager) ForgetTwoFactorClient(ctx context.Context) error

func (*SignInManager) GetTwoFactorAuthenticationUser

func (s *SignInManager) GetTwoFactorAuthenticationUser(ctx context.Context) (*User, error)

func (*SignInManager) IsSignedIn

func (s *SignInManager) IsSignedIn(ctx context.Context) (bool, error)

func (*SignInManager) IsTwoFactorClientRemembered

func (s *SignInManager) IsTwoFactorClientRemembered(ctx context.Context, u *User) (bool, error)

func (*SignInManager) PasswordSignIn

func (s *SignInManager) PasswordSignIn(ctx context.Context, u *User, pwd string, isPersistent bool, tryLockoutOnFailure bool) error

func (*SignInManager) PasswordSignInWithEmail

func (s *SignInManager) PasswordSignInWithEmail(ctx context.Context, email, pwd string, isPersistent bool, tryLockoutOnFailure bool) (error, string)

func (*SignInManager) PasswordSignInWithPhone

func (s *SignInManager) PasswordSignInWithPhone(ctx context.Context, phone, pwd string, isPersistent bool, tryLockoutOnFailure bool) (error, string)

func (*SignInManager) PasswordSignInWithUsername

func (s *SignInManager) PasswordSignInWithUsername(ctx context.Context, username, pwd string, isPersistent bool, tryLockoutOnFailure bool) (error, string)

func (*SignInManager) RememberTwoFactorClient

func (s *SignInManager) RememberTwoFactorClient(ctx context.Context, u *User) error

func (*SignInManager) SignIn

func (s *SignInManager) SignIn(ctx context.Context, u *User, isPersistent bool) error

func (*SignInManager) SignOut

func (s *SignInManager) SignOut(ctx context.Context) error

func (*SignInManager) TwoFactorAuthenticatorSignIn

func (s *SignInManager) TwoFactorAuthenticatorSignIn(ctx context.Context, code string, isPersistent, rememberClient bool) error

func (*SignInManager) TwoFactorSignIn

func (s *SignInManager) TwoFactorSignIn(ctx context.Context, provider, code string, isPersistent, rememberClient bool) error

func (*SignInManager) ValidateSecurityStamp

func (s *SignInManager) ValidateSecurityStamp(ctx context.Context, u *User, securityStamp string)

type TokenPurpose

type TokenPurpose string

type TwoStepTokenProvider

type TwoStepTokenProvider[T proto.Message] struct {
	// contains filtered or unexported fields
}

func NewTwoStepTokenProvider

func NewTwoStepTokenProvider[T proto.Message](creator func() T, proxy cache.CacheInterface[string]) *TwoStepTokenProvider[T]

func (*TwoStepTokenProvider[T]) Generate

func (p *TwoStepTokenProvider[T]) Generate(ctx context.Context, purpose TokenPurpose, payload T, duration time.Duration) (string, error)

func (*TwoStepTokenProvider[T]) Name

func (p *TwoStepTokenProvider[T]) Name() string

func (*TwoStepTokenProvider[T]) Retrieve

func (p *TwoStepTokenProvider[T]) Retrieve(ctx context.Context, purpose TokenPurpose, token string) (T, error)

type UpdateUserSetting

type UpdateUserSetting struct {
	Key string
	//Value new value
	Value  *data.Value
	Delete bool
}

type User

type User struct {
	kitgorm.UIDBase        `json:",squash"`
	concurrency.HasVersion `gorm:"type:char(36)"`
	kitgorm.AuditedModel
	kitgorm.AggRoot

	DeletedAt gorm.DeletedAt `gorm:"index"`

	Name      *string `json:"name"`
	FirstName *string `json:"first_name"`
	LastName  *string `json:"last_name"`

	Username *string `json:"username"`
	// NormalizedUsername uppercase normalized userName
	NormalizedUsername *string `json:"normalized_username" gorm:"index:,size:200"`

	// Phone
	Phone          *string `json:"phone" gorm:"index:,size:200"`
	PhoneConfirmed bool    `json:"phone_confirmed"`

	// Email
	Email *string `json:"email"`
	// NormalizedEmail uppercase normalized email
	NormalizedEmail *string `json:"normalized_email" gorm:"index:,size:200"`
	EmailConfirmed  bool    `json:"email_confirmed"`

	// Password hashed
	Password *string `json:"password"`

	//Security
	AccessFailedCount int        `json:"accessFailedCount"`
	LastLoginAttempt  *time.Time `json:"lastLoginAttempt"`
	LockoutEndDateUtc *time.Time `json:"lockoutEndDateUtc"`

	//2FA
	TwoFactorEnabled bool `json:"two_factor_enabled"`

	Roles []Role `gorm:"many2many:user_roles"`

	Location *string `json:"location"`
	Tags     *string `json:"tags"`

	// Avatar could be an id of asset or simple url
	Avatar   *string    `json:"avatar"`
	Birthday *time.Time `json:"birthday"`
	Gender   *string    `json:"gender"`

	Tenants []UserTenant `json:"tenants"`

	Extra data.JSONMap
	//creation tenant
	CreatedTenant *string `json:"created_tenant"`
}

func (*User) CheckInCurrentTenant

func (u *User) CheckInCurrentTenant(ctx context.Context) error

func (*User) SetEmail

func (u *User) SetEmail(email string, confirmed bool)

func (*User) SetPhone

func (u *User) SetPhone(phone string, confirmed bool)

type UserAddress

type UserAddress struct {
	gorm.UIDBase
	gorm.AuditedModel
	UserId   uuid.UUID         `json:"user_id" gorm:"index"`
	Phone    string            `json:"phone"`
	Usage    string            `json:"usage"`
	Prefer   bool              `json:"prefer"`
	Address  lbs.AddressEntity `json:"address" gorm:"embedded"`
	Metadata data.JSONMap      `json:"metadata"`
}

type UserAddressRepo

type UserAddressRepo interface {
	data.Repo[UserAddress, string, interface{}]
	FindByUser(ctx context.Context, userId string) ([]*UserAddress, error)
	SetPrefer(ctx context.Context, addr *UserAddress) error
}

type UserLogin

type UserLogin struct {
	UserId        uuid.UUID `gorm:"type:char(36);primaryKey" json:"user_id"`
	LoginProvider string    `gorm:"primaryKey" json:"login_provider"`
	ProviderKey   string    `gorm:"index" json:"provider_key"`
}

type UserManager

type UserManager struct {
	// contains filtered or unexported fields
}

func NewUserManager

func NewUserManager(
	cfg *conf.UserConf,
	userRepo UserRepo,
	pwdHasher PasswordHasher,
	userValidator UserValidator,
	pwdValidator PasswordValidator,
	lookupNormalizer LookupNormalizer,
	userTokenRepo UserTokenRepo,
	refreshTokenRepo RefreshTokenRepo,
	userTenantRepo UserTenantRepo,
	emailToken *EmailTokenProvider,
	phoneToken *PhoneTokenProvider,
	otp OtpTokenProvider,
	strCache cache.CacheInterface[string],
	logger log.Logger) *UserManager

func (*UserManager) AddLogin

func (um *UserManager) AddLogin(ctx context.Context, user *User, logins []UserLogin) error

func (*UserManager) AddToRole

func (um *UserManager) AddToRole(ctx context.Context, user *User, role *Role) error

func (*UserManager) ChangePassword

func (um *UserManager) ChangePassword(ctx context.Context, user *User, current string, newPwd string) error

func (*UserManager) ChangePasswordByToken

func (um *UserManager) ChangePasswordByToken(ctx context.Context, token, newPwd string) error

func (*UserManager) CheckDeleted

func (um *UserManager) CheckDeleted(ctx context.Context, u *User) (bool, error)

func (*UserManager) CheckLocked

func (um *UserManager) CheckLocked(ctx context.Context, u *User) (bool, error)

func (*UserManager) CheckPassword

func (um *UserManager) CheckPassword(ctx context.Context, user *User, password string) error

func (*UserManager) Count

func (um *UserManager) Count(ctx context.Context, query *v1.ListUsersRequest) (total int64, filtered int64, err error)

func (*UserManager) CountAdmin

func (um *UserManager) CountAdmin(ctx context.Context, query *v1.AdminListUsersRequest) (total int64, filtered int64, err error)

func (*UserManager) Create

func (um *UserManager) Create(ctx context.Context, u *User) (err error)

func (*UserManager) CreateWithPassword

func (um *UserManager) CreateWithPassword(ctx context.Context, u *User, pwd string, validate bool) (err error)

func (*UserManager) Delete

func (um *UserManager) Delete(ctx context.Context, user *User) error

func (*UserManager) FindByEmail

func (um *UserManager) FindByEmail(ctx context.Context, email string) (user *User, err error)

func (*UserManager) FindByID

func (um *UserManager) FindByID(ctx context.Context, id string) (user *User, err error)

func (*UserManager) FindByIdentity

func (um *UserManager) FindByIdentity(ctx context.Context, identity string) (user *User, err error)

func (*UserManager) FindByLogin

func (um *UserManager) FindByLogin(ctx context.Context, loginProvider string, providerKey string) (*User, error)

func (*UserManager) FindByName

func (um *UserManager) FindByName(ctx context.Context, name string) (user *User, err error)

func (*UserManager) FindByPhone

func (um *UserManager) FindByPhone(ctx context.Context, phone string) (user *User, err error)

func (*UserManager) GenerateEmailForgetPasswordToken

func (um *UserManager) GenerateEmailForgetPasswordToken(ctx context.Context, user *User) (string, error)

func (*UserManager) GenerateEmailLoginPasswordlessToken

func (um *UserManager) GenerateEmailLoginPasswordlessToken(ctx context.Context, email string) (string, error)

func (*UserManager) GenerateForgetPasswordTwoStepToken

func (um *UserManager) GenerateForgetPasswordTwoStepToken(ctx context.Context, user *User) (string, error)

func (*UserManager) GeneratePhoneForgetPasswordToken

func (um *UserManager) GeneratePhoneForgetPasswordToken(ctx context.Context, user *User) (string, error)

func (*UserManager) GeneratePhoneLoginPasswordlessToken

func (um *UserManager) GeneratePhoneLoginPasswordlessToken(ctx context.Context, phone string) (string, error)

func (*UserManager) GenerateRememberToken

func (um *UserManager) GenerateRememberToken(ctx context.Context, duration time.Duration, uid uuid.UUID) (string, error)

func (*UserManager) GetRoles

func (um *UserManager) GetRoles(ctx context.Context, userId string) ([]Role, error)

func (*UserManager) GetUserRoleIds

func (um *UserManager) GetUserRoleIds(ctx context.Context, userId string, currentTenantOnly bool) ([]*UserRoleCacheItem_UserRole, error)

func (*UserManager) IsInTenant

func (um *UserManager) IsInTenant(ctx context.Context, uid, tenantId string) (bool, error)

func (*UserManager) JoinTenant

func (um *UserManager) JoinTenant(ctx context.Context, uid, tenantId string) error

JoinTenant add user into tenant. safe to call when user already in

func (*UserManager) List

func (um *UserManager) List(ctx context.Context, query *v1.ListUsersRequest) ([]*User, error)

func (*UserManager) ListAdmin

func (um *UserManager) ListAdmin(ctx context.Context, query *v1.AdminListUsersRequest) ([]*User, error)

func (*UserManager) ListLogin

func (um *UserManager) ListLogin(ctx context.Context, user *User) ([]*UserLogin, error)

func (*UserManager) RefreshRememberToken

func (um *UserManager) RefreshRememberToken(ctx context.Context, token string, duration time.Duration) (*User, string, error)

func (*UserManager) RemoveFromRole

func (um *UserManager) RemoveFromRole(ctx context.Context, user *User, role *Role) error

func (*UserManager) RemoveFromTenant

func (um *UserManager) RemoveFromTenant(ctx context.Context, uid, tenantId string) error

func (*UserManager) RemoveUserRoleCache

func (um *UserManager) RemoveUserRoleCache(ctx context.Context, userId string) error

func (*UserManager) Update

func (um *UserManager) Update(ctx context.Context, user *User, q query.Select) (err error)

func (*UserManager) UpdatePassword

func (um *UserManager) UpdatePassword(ctx context.Context, user *User, newPwd string) error

func (*UserManager) UpdateRoles

func (um *UserManager) UpdateRoles(ctx context.Context, user *User, roles []Role) error

func (*UserManager) VerifyEmailForgetPasswordToken

func (um *UserManager) VerifyEmailForgetPasswordToken(ctx context.Context, email, token string) error

func (*UserManager) VerifyEmailLoginPasswordlessToken

func (um *UserManager) VerifyEmailLoginPasswordlessToken(ctx context.Context, email, token string) (*User, error)

func (*UserManager) VerifyPhoneForgetPasswordToken

func (um *UserManager) VerifyPhoneForgetPasswordToken(ctx context.Context, phone, token string) error

func (*UserManager) VerifyPhoneLoginPasswordlessToken

func (um *UserManager) VerifyPhoneLoginPasswordlessToken(ctx context.Context, phone, token string) (*User, error)

type UserRepo

type UserRepo interface {
	data.Repo[User, string, *v1.ListUsersRequest]

	ListAdmin(ctx context.Context, query *v1.AdminListUsersRequest) ([]*User, error)
	CountAdmin(ctx context.Context, query *v1.AdminListUsersRequest) (total int64, filtered int64, err error)

	FindByID(ctx context.Context, id string) (*User, error)
	FindByName(ctx context.Context, name string) (*User, error)
	FindByPhone(ctx context.Context, phone string) (*User, error)
	FindByEmail(ctx context.Context, email string) (*User, error)

	AddLogin(ctx context.Context, user *User, userLogin *UserLogin) error
	RemoveLogin(ctx context.Context, user *User, loginProvider string, providerKey string) error
	ListLogin(ctx context.Context, user *User) ([]*UserLogin, error)
	FindByLogin(ctx context.Context, loginProvider string, providerKey string) (*User, error)

	SetToken(ctx context.Context, user *User, loginProvider string, name string, value string) error
	RemoveToken(ctx context.Context, user *User, loginProvider string, name string) error
	GetToken(ctx context.Context, user *User, loginProvider string, name string) (*string, error)

	GetRoles(ctx context.Context, userId string) ([]Role, error)
	UpdateRoles(ctx context.Context, user *User, roles []Role) error
	AddToRole(ctx context.Context, user *User, role *Role) error
	RemoveFromRole(ctx context.Context, user *User, role *Role) error
}

type UserRole

type UserRole struct {
	gorm.MultiTenancy `gorm:"primaryKey"`
	UserID            uuid.UUID `gorm:"type:char(36);primaryKey"`
	RoleID            uuid.UUID `gorm:"type:char(36);primaryKey"`
}

type UserRoleCacheItem

type UserRoleCacheItem struct {
	Role []*UserRoleCacheItem_UserRole `protobuf:"bytes,1,rep,name=role,proto3" json:"role,omitempty"`
	// contains filtered or unexported fields
}

func (*UserRoleCacheItem) Descriptor deprecated

func (*UserRoleCacheItem) Descriptor() ([]byte, []int)

Deprecated: Use UserRoleCacheItem.ProtoReflect.Descriptor instead.

func (*UserRoleCacheItem) GetRole

func (*UserRoleCacheItem) ProtoMessage

func (*UserRoleCacheItem) ProtoMessage()

func (*UserRoleCacheItem) ProtoReflect

func (x *UserRoleCacheItem) ProtoReflect() protoreflect.Message

func (*UserRoleCacheItem) Reset

func (x *UserRoleCacheItem) Reset()

func (*UserRoleCacheItem) String

func (x *UserRoleCacheItem) String() string

func (*UserRoleCacheItem) Validate

func (m *UserRoleCacheItem) Validate() error

Validate checks the field values on UserRoleCacheItem with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*UserRoleCacheItem) ValidateAll

func (m *UserRoleCacheItem) ValidateAll() error

ValidateAll checks the field values on UserRoleCacheItem with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in UserRoleCacheItemMultiError, or nil if none found.

type UserRoleCacheItemMultiError

type UserRoleCacheItemMultiError []error

UserRoleCacheItemMultiError is an error wrapping multiple validation errors returned by UserRoleCacheItem.ValidateAll() if the designated constraints aren't met.

func (UserRoleCacheItemMultiError) AllErrors

func (m UserRoleCacheItemMultiError) AllErrors() []error

AllErrors returns a list of validation violation errors.

func (UserRoleCacheItemMultiError) Error

Error returns a concatenation of all the error messages it wraps.

type UserRoleCacheItemValidationError

type UserRoleCacheItemValidationError struct {
	// contains filtered or unexported fields
}

UserRoleCacheItemValidationError is the validation error returned by UserRoleCacheItem.Validate if the designated constraints aren't met.

func (UserRoleCacheItemValidationError) Cause

Cause function returns cause value.

func (UserRoleCacheItemValidationError) Error

Error satisfies the builtin error interface

func (UserRoleCacheItemValidationError) ErrorName

ErrorName returns error name.

func (UserRoleCacheItemValidationError) Field

Field function returns field value.

func (UserRoleCacheItemValidationError) Key

Key function returns key value.

func (UserRoleCacheItemValidationError) Reason

Reason function returns reason value.

type UserRoleCacheItem_UserRole

type UserRoleCacheItem_UserRole struct {
	RoleId   string `protobuf:"bytes,1,opt,name=role_id,json=roleId,proto3" json:"role_id,omitempty"`
	TenantId string `protobuf:"bytes,2,opt,name=tenant_id,json=tenantId,proto3" json:"tenant_id,omitempty"`
	// contains filtered or unexported fields
}

func (*UserRoleCacheItem_UserRole) Descriptor deprecated

func (*UserRoleCacheItem_UserRole) Descriptor() ([]byte, []int)

Deprecated: Use UserRoleCacheItem_UserRole.ProtoReflect.Descriptor instead.

func (*UserRoleCacheItem_UserRole) GetRoleId

func (x *UserRoleCacheItem_UserRole) GetRoleId() string

func (*UserRoleCacheItem_UserRole) GetTenantId

func (x *UserRoleCacheItem_UserRole) GetTenantId() string

func (*UserRoleCacheItem_UserRole) ProtoMessage

func (*UserRoleCacheItem_UserRole) ProtoMessage()

func (*UserRoleCacheItem_UserRole) ProtoReflect

func (*UserRoleCacheItem_UserRole) Reset

func (x *UserRoleCacheItem_UserRole) Reset()

func (*UserRoleCacheItem_UserRole) String

func (x *UserRoleCacheItem_UserRole) String() string

func (*UserRoleCacheItem_UserRole) Validate

func (m *UserRoleCacheItem_UserRole) Validate() error

Validate checks the field values on UserRoleCacheItem_UserRole with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*UserRoleCacheItem_UserRole) ValidateAll

func (m *UserRoleCacheItem_UserRole) ValidateAll() error

ValidateAll checks the field values on UserRoleCacheItem_UserRole with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in UserRoleCacheItem_UserRoleMultiError, or nil if none found.

type UserRoleCacheItem_UserRoleMultiError

type UserRoleCacheItem_UserRoleMultiError []error

UserRoleCacheItem_UserRoleMultiError is an error wrapping multiple validation errors returned by UserRoleCacheItem_UserRole.ValidateAll() if the designated constraints aren't met.

func (UserRoleCacheItem_UserRoleMultiError) AllErrors

AllErrors returns a list of validation violation errors.

func (UserRoleCacheItem_UserRoleMultiError) Error

Error returns a concatenation of all the error messages it wraps.

type UserRoleCacheItem_UserRoleValidationError

type UserRoleCacheItem_UserRoleValidationError struct {
	// contains filtered or unexported fields
}

UserRoleCacheItem_UserRoleValidationError is the validation error returned by UserRoleCacheItem_UserRole.Validate if the designated constraints aren't met.

func (UserRoleCacheItem_UserRoleValidationError) Cause

Cause function returns cause value.

func (UserRoleCacheItem_UserRoleValidationError) Error

Error satisfies the builtin error interface

func (UserRoleCacheItem_UserRoleValidationError) ErrorName

ErrorName returns error name.

func (UserRoleCacheItem_UserRoleValidationError) Field

Field function returns field value.

func (UserRoleCacheItem_UserRoleValidationError) Key

Key function returns key value.

func (UserRoleCacheItem_UserRoleValidationError) Reason

Reason function returns reason value.

type UserSeed

type UserSeed struct {
	// contains filtered or unexported fields
}

func NewUserSeed

func NewUserSeed(um *UserManager, rm *RoleManager) *UserSeed

func (*UserSeed) Seed

func (u *UserSeed) Seed(ctx context.Context, sCtx *seed.Context) error

type UserSetting

type UserSetting struct {
	gorm.UIDBase
	UserId string     `json:"user_id" gorm:"index"`
	Key    string     `json:"key" gorm:"index"`
	Value  data.Value `gorm:"embedded"`
}

UserSetting contains key/value pairs of user settings

type UserSettingRepo

type UserSettingRepo interface {
	data.Repo[UserSetting, string, *v1.GetSettingsRequest]
	FindByUser(ctx context.Context, userId string, query *v1.GetSettingsRequest) ([]*UserSetting, error)
	UpdateByUser(ctx context.Context, userId string, updateBatch []UpdateUserSetting) error
}

type UserTenant

type UserTenant struct {
	gorm2.AuditedModel
	UserId   string           `gorm:"type:char(36);primary_key" json:"user_id"`
	TenantId string           `gorm:"type:char(36);primary_key" json:"tenant_id" `
	JoinTime time.Time        `json:"join_time"`
	Status   UserTenantStatus `json:"status;index"`
	Extra    data.JSONMap
}

func (*UserTenant) GetTenantId

func (u *UserTenant) GetTenantId() string

func (*UserTenant) SetTenantId

func (u *UserTenant) SetTenantId(id string) *UserTenant

type UserTenantRepo

type UserTenantRepo interface {
	JoinTenant(ctx context.Context, userId string, tenantId string, status UserTenantStatus) (*UserTenant, error)
	RemoveFromTenant(ctx context.Context, userId string, tenantId string) error
	Get(ctx context.Context, userId string, tenantId string) (*UserTenant, error)
	IsIn(ctx context.Context, userId string, tenantId string) (bool, error)
	Update(ctx context.Context, userTenant *UserTenant) error
}

type UserTenantStatus

type UserTenantStatus int32
const (
	Active   UserTenantStatus = 0
	Inactive UserTenantStatus = 1
)

func (UserTenantStatus) String

func (p UserTenantStatus) String() string

type UserToken

type UserToken struct {
	gorm.AuditedModel
	DeletedAt     gorm2.DeletedAt `gorm:"index"`
	UserId        uuid.UUID       `gorm:"type:char(36);primaryKey" json:"user_id"`
	LoginProvider string          `gorm:"primaryKey" json:"login_provider"`
	Name          string          `gorm:"primaryKey" json:"name"`
	Value         string          `json:"value"`
}

UserToken stores external login token

type UserTokenProvider

type UserTokenProvider interface {
	// Name of this provider
	Name() string
	Generate(ctx context.Context, purpose TokenPurpose, user *User, duration time.Duration) (token string, err error)
	Validate(ctx context.Context, purpose TokenPurpose, token string, user *User) (bool, error)
	CanGenerate(ctx context.Context, user *User) error
}

type UserTokenRepo

type UserTokenRepo interface {
	FindByUserIdAndLoginProvider(ctx context.Context, userId, loginProvider string) ([]*UserToken, error)
	FindByUserIdAndLoginProviderAndName(ctx context.Context, userId, loginProvider, name string) (*UserToken, error)
	DeleteByUserIdAndLoginProvider(ctx context.Context, userId, loginProvider string) error
	DeleteByUserIdAndLoginProviderAndName(ctx context.Context, userId, loginProvider, name string) error
	Create(ctx context.Context, userId, loginProvider, name, value string) (*UserToken, error)
}

type UserValidator

type UserValidator interface {
	Validate(ctx context.Context, um *UserManager, user *User) (err error)
}

UserValidator validate user before create and update

func NewUserValidator

func NewUserValidator() UserValidator

type WeChatMiniProgramLoginTwoStepTokenPayload

type WeChatMiniProgramLoginTwoStepTokenPayload struct {
	AppId      string `protobuf:"bytes,1,opt,name=app_id,json=appId,proto3" json:"app_id,omitempty"`
	SessionKey string `protobuf:"bytes,2,opt,name=session_key,json=sessionKey,proto3" json:"session_key,omitempty"`
	OpenId     string `protobuf:"bytes,3,opt,name=open_id,json=openId,proto3" json:"open_id,omitempty"`
	UnionId    string `protobuf:"bytes,4,opt,name=union_id,json=unionId,proto3" json:"union_id,omitempty"`
	Step       string `protobuf:"bytes,5,opt,name=step,proto3" json:"step,omitempty"`
	// contains filtered or unexported fields
}

func (*WeChatMiniProgramLoginTwoStepTokenPayload) Descriptor deprecated

func (*WeChatMiniProgramLoginTwoStepTokenPayload) Descriptor() ([]byte, []int)

Deprecated: Use WeChatMiniProgramLoginTwoStepTokenPayload.ProtoReflect.Descriptor instead.

func (*WeChatMiniProgramLoginTwoStepTokenPayload) GetAppId

func (*WeChatMiniProgramLoginTwoStepTokenPayload) GetOpenId

func (*WeChatMiniProgramLoginTwoStepTokenPayload) GetSessionKey

func (*WeChatMiniProgramLoginTwoStepTokenPayload) GetStep

func (*WeChatMiniProgramLoginTwoStepTokenPayload) GetUnionId

func (*WeChatMiniProgramLoginTwoStepTokenPayload) ProtoMessage

func (*WeChatMiniProgramLoginTwoStepTokenPayload) ProtoReflect

func (*WeChatMiniProgramLoginTwoStepTokenPayload) Reset

func (*WeChatMiniProgramLoginTwoStepTokenPayload) String

func (*WeChatMiniProgramLoginTwoStepTokenPayload) Validate

Validate checks the field values on WeChatMiniProgramLoginTwoStepTokenPayload with the rules defined in the proto definition for this message. If any rules are violated, the first error encountered is returned, or nil if there are no violations.

func (*WeChatMiniProgramLoginTwoStepTokenPayload) ValidateAll

ValidateAll checks the field values on WeChatMiniProgramLoginTwoStepTokenPayload with the rules defined in the proto definition for this message. If any rules are violated, the result is a list of violation errors wrapped in WeChatMiniProgramLoginTwoStepTokenPayloadMultiError, or nil if none found.

type WeChatMiniProgramLoginTwoStepTokenPayloadMultiError

type WeChatMiniProgramLoginTwoStepTokenPayloadMultiError []error

WeChatMiniProgramLoginTwoStepTokenPayloadMultiError is an error wrapping multiple validation errors returned by WeChatMiniProgramLoginTwoStepTokenPayload.ValidateAll() if the designated constraints aren't met.

func (WeChatMiniProgramLoginTwoStepTokenPayloadMultiError) AllErrors

AllErrors returns a list of validation violation errors.

func (WeChatMiniProgramLoginTwoStepTokenPayloadMultiError) Error

Error returns a concatenation of all the error messages it wraps.

type WeChatMiniProgramLoginTwoStepTokenPayloadValidationError

type WeChatMiniProgramLoginTwoStepTokenPayloadValidationError struct {
	// contains filtered or unexported fields
}

WeChatMiniProgramLoginTwoStepTokenPayloadValidationError is the validation error returned by WeChatMiniProgramLoginTwoStepTokenPayload.Validate if the designated constraints aren't met.

func (WeChatMiniProgramLoginTwoStepTokenPayloadValidationError) Cause

Cause function returns cause value.

func (WeChatMiniProgramLoginTwoStepTokenPayloadValidationError) Error

Error satisfies the builtin error interface

func (WeChatMiniProgramLoginTwoStepTokenPayloadValidationError) ErrorName

ErrorName returns error name.

func (WeChatMiniProgramLoginTwoStepTokenPayloadValidationError) Field

Field function returns field value.

func (WeChatMiniProgramLoginTwoStepTokenPayloadValidationError) Key

Key function returns key value.

func (WeChatMiniProgramLoginTwoStepTokenPayloadValidationError) Reason

Reason function returns reason value.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL