user

package
v0.0.0-...-8122643 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorCodeDuplicateEmail string = "duplicate_email"
View Source
const ErrorCodeDuplicateLogin string = "duplicate_login"
View Source
const ErrorCodeDuplicatePhone string = "duplicate_phone"

Variables

View Source
var ErrorDescriptions = map[string]string{
	ErrorCodeDuplicateLogin: "Login already occupied",
	ErrorCodeDuplicateEmail: "Email address is already in use",
	ErrorCodeDuplicatePhone: "Phone number is already in use",
}
View Source
var ErrorHttpCodes = map[string]int{}

Functions

func FindByLogin

func FindByLogin(controller crud.CRUD, ctx op_context.Context, login string, user interface{}, dest ...interface{}) (bool, error)

func FindUser

func FindUser[UserType User](u UserFinder[UserType], ctx op_context.Context, id string, idIsLogin ...bool) (user UserType, err error)

Types

type AuthUserFinderBase

type AuthUserFinderBase struct {
	crud.WithCRUDBase
	// contains filtered or unexported fields
}

func NewAuthUserFinder

func NewAuthUserFinder(userBuilder func() User, cruds ...crud.CRUD) *AuthUserFinderBase

func (*AuthUserFinderBase) FindAuthUser

func (a *AuthUserFinderBase) FindAuthUser(ctx op_context.Context, login string) (auth.User, error)

type CheckDuplicateField

type CheckDuplicateField struct {
	Name      string
	Value     interface{}
	ErrorCode string
}

type MainFieldSetters

type MainFieldSetters interface {
	SetPassword(ctx op_context.Context, id string, password string, idIsLogin ...bool) error
	SetPhone(ctx op_context.Context, id string, phone string, idIsLogin ...bool) error
	SetEmail(ctx op_context.Context, id string, email string, idIsLogin ...bool) error
	SetBlocked(ctx op_context.Context, id string, blocked bool, idIsLogin ...bool) error
}

type OpLogUser

type OpLogUser struct {
	oplog.OplogBase
	OpLogUserHolder
}

func (*OpLogUser) Login

func (o *OpLogUser) Login() string

func (*OpLogUser) SetLogin

func (o *OpLogUser) SetLogin(val string)

func (*OpLogUser) SetUserId

func (o *OpLogUser) SetUserId(val string)

func (*OpLogUser) UserId

func (o *OpLogUser) UserId() string

type OpLogUserHolder

type OpLogUserHolder struct {
	Login  string `gorm:"index" json:"login"`
	UserId string `gorm:"index" json:"user_id"`
}

type OpLogUserI

type OpLogUserI interface {
	oplog.Oplog
	Login() string
	UserId() string
	SetLogin(string)
	SetUserId(string)
}

type SetUserFields

type SetUserFields[UserType interface{}] func(ctx op_context.Context, user UserType) ([]CheckDuplicateField, error)

func Email

func Email[UserType User](email string, userSample ...UserType) SetUserFields[UserType]

func Phone

func Phone[UserType User](phone string, userSample ...UserType) SetUserFields[UserType]

type User

type User interface {
	common.Object
	auth.User
	auth_login_phash.User
	auth_sms.UserWithPhone

	SetLogin(login string)
	SetPhone(phone string)
	SetBlocked(val bool)

	Email() string
	SetEmail(email string)

	DbUser() interface{}

	ToCmd(password string) interface{}
}

type UserBase

type UserBase struct {
	UserBaseDB
}

func NewUser

func NewUser() *UserBase

func (*UserBase) DbUser

func (u *UserBase) DbUser() interface{}

type UserBaseDB

func (*UserBaseDB) ToCmd

func (u *UserBaseDB) ToCmd(password string) interface{}

type UserBaseFields

type UserBaseFields struct {
	UserPhone
	UserEmail
	UserBlocked
	LOGIN string `gorm:"uniqueIndex" json:"login"`
}

func (*UserBaseFields) Display

func (u *UserBaseFields) Display() string

func (*UserBaseFields) Email

func (u *UserBaseFields) Email() string

func (*UserBaseFields) IsBlocked

func (u *UserBaseFields) IsBlocked() bool

func (*UserBaseFields) Login

func (u *UserBaseFields) Login() string

func (*UserBaseFields) Phone

func (u *UserBaseFields) Phone() string

func (*UserBaseFields) SetBlocked

func (u *UserBaseFields) SetBlocked(val bool)

func (*UserBaseFields) SetEmail

func (u *UserBaseFields) SetEmail(email string)

func (*UserBaseFields) SetLogin

func (u *UserBaseFields) SetLogin(login string)

func (*UserBaseFields) SetPhone

func (u *UserBaseFields) SetPhone(phone string)

func (*UserBaseFields) SetUserFields

func (u *UserBaseFields) SetUserFields(ctx op_context.Context, user User) ([]CheckDuplicateField, error)

type UserBlocked

type UserBlocked struct {
	BLOCKED bool `gorm:"index" json:"blocked"`
}

type UserController

type UserController[UserType User] interface {
	MainFieldSetters
	UserFinder[UserType]

	Add(ctx op_context.Context, login string, password string, extraFieldsSetters ...SetUserFields[UserType]) (UserType, error)
	FindUsers(ctx op_context.Context, filter *db.Filter) ([]UserType, int64, error)

	SetUserBuilder(builder func() UserType)
	MakeUser() UserType

	SetOplogBuilder(builder func() OpLogUserI)
	OpLog(ctx op_context.Context, op string, userId string, login string)
}

type UserControllerBase

type UserControllerBase[UserType User] struct {
	// contains filtered or unexported fields
}

func LocalUserController

func LocalUserController[UserType User]() *UserControllerBase[UserType]

func (*UserControllerBase[UserType]) Add

func (u *UserControllerBase[UserType]) Add(ctx op_context.Context, login string, password string, extraFieldsSetters ...SetUserFields[UserType]) (UserType, error)

func (*UserControllerBase[UserType]) CRUD

func (u *UserControllerBase[UserType]) CRUD() crud.CRUD

func (*UserControllerBase[UserType]) Find

func (u *UserControllerBase[UserType]) Find(ctx op_context.Context, id string) (UserType, error)

func (*UserControllerBase[UserType]) FindByLogin

func (u *UserControllerBase[UserType]) FindByLogin(ctx op_context.Context, login string) (UserType, error)

func (*UserControllerBase[UserType]) FindUsers

func (u *UserControllerBase[UserType]) FindUsers(ctx op_context.Context, filter *db.Filter) ([]UserType, int64, error)

func (*UserControllerBase[UserType]) MakeUser

func (u *UserControllerBase[UserType]) MakeUser() UserType

func (*UserControllerBase[UserType]) OpLog

func (u *UserControllerBase[UserType]) OpLog(ctx op_context.Context, op string, userId string, login string)

func (*UserControllerBase[UserType]) SetBlocked

func (u *UserControllerBase[UserType]) SetBlocked(ctx op_context.Context, id string, blocked bool, idIsLogin ...bool) error

func (*UserControllerBase[UserType]) SetEmail

func (u *UserControllerBase[UserType]) SetEmail(ctx op_context.Context, id string, email string, idIsLogin ...bool) error

func (*UserControllerBase[UserType]) SetOplogBuilder

func (u *UserControllerBase[UserType]) SetOplogBuilder(builder func() OpLogUserI)

func (*UserControllerBase[UserType]) SetPassword

func (u *UserControllerBase[UserType]) SetPassword(ctx op_context.Context, id string, password string, idIsLogin ...bool) error

func (*UserControllerBase[UserType]) SetPhone

func (u *UserControllerBase[UserType]) SetPhone(ctx op_context.Context, id string, phone string, idIsLogin ...bool) error

func (*UserControllerBase[UserType]) SetUserBuilder

func (u *UserControllerBase[UserType]) SetUserBuilder(userBuilder func() UserType)

func (*UserControllerBase[UserType]) SetUserValidators

func (u *UserControllerBase[UserType]) SetUserValidators(validators auth_session.UserValidators)

type UserEmail

type UserEmail struct {
	EMAIL string `gorm:"index" json:"email,omitempty" validate:"omitempty,email" vmessage:"Invalid email format"`
}

type UserFieldsSetter

type UserFieldsSetter[T User] interface {
	Login() string
	Password() string
	SetUserFields(ctx op_context.Context, user T) ([]CheckDuplicateField, error)
}

type UserFieldsSetterBase

type UserFieldsSetterBase[T User] struct {
	UserFieldsWithPassword
}

type UserFieldsWithPassword

type UserFieldsWithPassword struct {
	UserBaseFields
	UserPlainPassword
}

func NewUserFieldsWihPassword

func NewUserFieldsWihPassword() *UserFieldsWithPassword

func (*UserFieldsWithPassword) Password

func (u *UserFieldsWithPassword) Password() string

func (*UserFieldsWithPassword) SetPassword

func (u *UserFieldsWithPassword) SetPassword(password string)

type UserFinder

type UserFinder[U User] interface {
	Find(ctx op_context.Context, id string) (U, error)
	FindByLogin(ctx op_context.Context, login string) (U, error)
}

type UserPhone

type UserPhone struct {
	PHONE string `gorm:"index" json:"phone,omitempty" validate:"omitempty,phone" vmessage:"Invalid phone format"`
}

type UserPlainPassword

type UserPlainPassword struct {
	PlainPassword string `gorm:"-:all" json:"password"`
}

type Users

type Users[UserType User] interface {
	auth_session.AuthUserManager
	UserController[UserType]
}

type UsersBase

type UsersBase[UserType User] struct {
	UsersValidator
	UserController[UserType]
	auth_session.AuthUserFinder
}

func (*UsersBase[UserType]) AuthUserManager

func (m *UsersBase[UserType]) AuthUserManager() auth_session.AuthUserManager

func (*UsersBase[UserType]) Construct

func (u *UsersBase[UserType]) Construct(userController UserController[UserType], authUserFinder ...auth_session.AuthUserFinder)

func (*UsersBase[UserType]) SetAuthUserFinder

func (u *UsersBase[UserType]) SetAuthUserFinder(authUserFinder auth_session.AuthUserFinder)

type UsersValidator

type UsersValidator struct {
	Validator            validator.Validator
	LoginValidationRules string
}

func (*UsersValidator) Init

func (u *UsersValidator) Init(vld validator.Validator, loginValidationRules ...string)

func (*UsersValidator) ValidateLogin

func (u *UsersValidator) ValidateLogin(login string) error

func (*UsersValidator) ValidatePassword

func (u *UsersValidator) ValidatePassword(password string) error

type UsersWithSession

type UsersWithSession[UserType User, SessionType auth_session.Session, SessionClientType auth_session.SessionClient] interface {
	Users[UserType]
	auth_session.SessionController
}

type UsersWithSessionBase

type UsersWithSessionBase[UserType User, SessionType auth_session.Session, SessionClientType auth_session.SessionClient] struct {
	UsersBase[UserType]
	auth_session.SessionController
}

func NewUsersWithSession

func NewUsersWithSession[UserType User, SessionType auth_session.Session, SessionClientType auth_session.SessionClient](
	userBuilder func() UserType,
	sessionBuilder func() SessionType,
	sessionClientBuilder func() SessionClientType,
	oplogBuilder func() OpLogUserI,
	config ...UsersWithSessionBaseConfig[UserType]) *UsersWithSessionBase[UserType, SessionType, SessionClientType]

func (*UsersWithSessionBase[UserType, SessionType, SessionClientType]) SessionManager

func (m *UsersWithSessionBase[UserType, SessionType, SessionClientType]) SessionManager() auth_session.SessionController

type UsersWithSessionBaseConfig

type UsersWithSessionBaseConfig[UserType User] struct {
	UserController    UserController[UserType]
	SessionController auth_session.SessionController
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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