Documentation
¶
Index ¶
- Constants
- Variables
- func CheckOptions(opt Options) error
- type AxthUser
- type DisplayUser
- type Enforcer
- func (e *Enforcer) CheckEmailExist(email string) (bool, error)
- func (e *Enforcer) CheckPhoneExist(phone string) (bool, error)
- func (e *Enforcer) CheckUserIdExist(userId string) (bool, error)
- func (e *Enforcer) FindUser(userId string) (*DisplayUser, error)
- func (e *Enforcer) Login(userId string, password string) (*DisplayUser, error)
- func (e *Enforcer) LoginWithEmail(email string, password string) (*DisplayUser, error)
- func (e *Enforcer) LoginWithPhone(phone string, password string) (*DisplayUser, error)
- func (e *Enforcer) Register(ru RegisterUser) (bool, error)
- func (e *Enforcer) ResetPassword(userId string, oldPwd string, newPwd string) (bool, error)
- func (e *Enforcer) UpdateUser(userId string, user AxthUser) (bool, error)
- type IEnforcer
- type Options
- type RegisterUser
Constants ¶
View Source
const ( // UserStatusNormal user status is normal UserStatusNormal = "normal" // UserStatusBanned user status is banned UserStatusBanned = "banned" )
View Source
const ( FieldId = "id" FieldEmail = "email" FieldPhone = "phone" FieldUserId = "userId" )
Variables ¶
Functions ¶
func CheckOptions ¶
Types ¶
type AxthUser ¶
type AxthUser struct { gorm.Model UserID string `gorm:"uniqueIndex;size:255"` DisplayName string `gorm:"size:255"` AvatarUrl string `gorm:"size:255"` Email string `gorm:"uniqueIndex;size:255"` Phone string `gorm:"uniqueIndex;size:255"` Password string `gorm:"size:255"` Status string `gorm:"size:255"` LoginFailedCount int LastLoginTime time.Time }
AxthUser user schema
func (AxthUser) ToDisplayUser ¶
func (r AxthUser) ToDisplayUser() *DisplayUser
type DisplayUser ¶
type DisplayUser struct { ID uint `json:"id"` UserID string `json:"user_id"` DisplayName string `json:"display_name"` AvatarUrl string `json:"avatar_url"` Email string `json:"email"` Phone string `json:"phone"` Status string `json:"status"` LoginFailedCount int `json:"login_failed_count"` CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` LastLoginTime time.Time `json:"last_login_time"` }
DisplayUser For user display
type Enforcer ¶
type Enforcer struct {
// contains filtered or unexported fields
}
func NewEnforcer ¶
NewEnforcer create a new enforcer
func (*Enforcer) CheckEmailExist ¶
CheckEmailExist check if email already exist
func (*Enforcer) CheckPhoneExist ¶
CheckPhoneExist check if phone already exist
func (*Enforcer) CheckUserIdExist ¶
CheckUserIdExist check if userId already exist
func (*Enforcer) FindUser ¶
func (e *Enforcer) FindUser(userId string) (*DisplayUser, error)
FindUser find a user
func (*Enforcer) Login ¶
func (e *Enforcer) Login(userId string, password string) (*DisplayUser, error)
Login user login with userId and password, default login method
func (*Enforcer) LoginWithEmail ¶
func (e *Enforcer) LoginWithEmail(email string, password string) (*DisplayUser, error)
LoginWithEmail user login with email
func (*Enforcer) LoginWithPhone ¶
func (e *Enforcer) LoginWithPhone(phone string, password string) (*DisplayUser, error)
LoginWithPhone user login with phone
func (*Enforcer) Register ¶
func (e *Enforcer) Register(ru RegisterUser) (bool, error)
Register register a user
func (*Enforcer) ResetPassword ¶
ResetPassword reset account password
type IEnforcer ¶
type IEnforcer interface { Login(userId string, password string) (*DisplayUser, error) LoginWithEmail(email string, password string) (*DisplayUser, error) LoginWithPhone(phone string, password string) (*DisplayUser, error) ResetPassword(userId string, oldPwd string, newPwd string) (bool, error) Register(ru RegisterUser) (bool, error) UpdateUser(userId string, user AxthUser) (bool, error) FindUser(userId string) (*DisplayUser, error) CheckUserIdExist(userId string) (bool, error) CheckEmailExist(email string) (bool, error) CheckPhoneExist(phone string) (bool, error) }
type Options ¶
type Options struct { // auto migrate inner table DbAutoMigrate bool // user max login failed times UserMaxLoginFailed int `validate:"gte=0"` // if user reach max login failed, wait for duration to unlock UserLoginFailedUnlockDuration time.Duration }
func DefaultOptions ¶
type RegisterUser ¶
type RegisterUser struct { UserID string `json:"user_id,omitempty"` DisplayName string `json:"display_name,omitempty"` AvatarUrl string `json:"avatar_url,omitempty"` Email string `json:"email,omitempty"` Phone string `json:"phone,omitempty"` Password string `json:"password,omitempty"` }
RegisterUser For user register
func (RegisterUser) ToAxUser ¶
func (u RegisterUser) ToAxUser() *AxthUser
Click to show internal directories.
Click to hide internal directories.