Documentation
¶
Index ¶
- Variables
- func RandomBytes() (string, error)
- func Timestamp() (string, error)
- type AccountMapper
- func (a *AccountMapper) Bind(uid string, account *user.Account) error
- func (a *AccountMapper) Find(keyword string, account string) (*AccountModel, error)
- func (a *AccountMapper) MustAccountToUID(account *user.Account) (uid string)
- func (a *AccountMapper) MustAccounts(uid string) *user.Accounts
- func (a *AccountMapper) MustBindAccount(uid string, account *user.Account)
- func (a *AccountMapper) MustUnbindAccount(uid string, account *user.Account)
- func (a *AccountMapper) Purge(string) error
- func (a *AccountMapper) Start() error
- func (a *AccountMapper) Stop() error
- func (a *AccountMapper) Unbind(uid string, account *user.Account) error
- type AccountModel
- type Config
- type HashFunc
- type PasswordMapper
- func (p *PasswordMapper) Find(uid string) (PasswordModel, error)
- func (p *PasswordMapper) InsertOrUpdate(model *PasswordModel) error
- func (p *PasswordMapper) MustUpdatePassword(uid string, password string)
- func (p *PasswordMapper) MustVerifyPassword(uid string, password string) bool
- func (p *PasswordMapper) PasswordChangeable() bool
- func (p *PasswordMapper) Purge(string) error
- func (p *PasswordMapper) Start() error
- func (p *PasswordMapper) Stop() error
- type PasswordModel
- type Tables
- type TokenMapper
- type TokenModel
- type User
- func (u *User) Account() *AccountMapper
- func (u *User) AccountTableName() string
- func (u *User) AddTablePrefix(prefix string)
- func (u *User) Password() *PasswordMapper
- func (u *User) PasswordTableName() string
- func (u *User) Token() *TokenMapper
- func (u *User) TokenTableName() string
- func (u *User) User() *UserMapper
- func (u *User) UserTableName() string
- type UserMapper
- func (u *UserMapper) IsAvailable(userstats status.Status) (bool, error)
- func (u *UserMapper) Label(userstats status.Status) (string, error)
- func (u *UserMapper) MustCreateStatus(uid string)
- func (u *UserMapper) MustListUsersByStatus(last string, limit int, reverse bool, statuses ...status.Status) []string
- func (u *UserMapper) MustLoadStatus(uid string) (status.Status, bool)
- func (u *UserMapper) MustRemoveStatus(uid string)
- func (u *UserMapper) MustUpdateStatus(uid string, userstatus status.Status)
- func (u *UserMapper) Purge(uid string) error
- func (u *UserMapper) Start() error
- func (u *UserMapper) Stop() error
- type UserModel
Constants ¶
This section is empty.
Variables ¶
var DefaultAccountMapperName = "account"
DefaultAccountMapperName default database table name for module account.
var DefaultHashMethod = "sha256"
DefaultHashMethod default hash method when created password data.
var DefaultPasswordMapperName = "password"
DefaultPasswordMapperName default database table name for module password.
var DefaultTokenMapperName = "token"
DefaultTokenMapperName default database table name for module token.
var DefaultUserMapperName = "user"
DefaultUserMapperName default database table name for module user.
var DirectiveFactory = func(loader func(v interface{}) error) (usersystem.Directive, error) { c := &Config{} err := loader(c) if err != nil { return nil, err } return c, nil }
var ErrHashMethodNotFound = errors.New("password hash method not found")
ErrHashMethodNotFound error raised when password hash method not found.
var HashFuncMap = map[string]HashFunc{ "sha256": func(key string, salt string, password string) ([]byte, error) { var val = []byte(key + salt + password) var s256 = sha256.New() s256.Write(val) val = s256.Sum(nil) s256.Write(val) return []byte(hex.EncodeToString(s256.Sum(nil))), nil }, }
HashFuncMap all available password hash func. You can insert custom hash func into this map.
var RandomBytesLength = 32
RandomBytesLength bytes length for RandomBytes function.
Functions ¶
func RandomBytes ¶
RandomBytes string generater return random bytes. Default length is 32 byte.You can change default length by change sqluesr.RandomBytesLength .
Types ¶
type AccountMapper ¶
type AccountMapper struct {
*modelmapper.ModelMapper
User *User
}
AccountMapper account mapper
func (*AccountMapper) Bind ¶
func (a *AccountMapper) Bind(uid string, account *user.Account) error
Bind bind account to user. Return any error if raised. If account exists, error user.ErrAccountBindingExists will raised.
func (*AccountMapper) Find ¶
func (a *AccountMapper) Find(keyword string, account string) (*AccountModel, error)
Find find account by given keyword and account. Return account model and any error if raised.
func (*AccountMapper) MustAccountToUID ¶
func (a *AccountMapper) MustAccountToUID(account *user.Account) (uid string)
MustAccountToUID query uid by user account. Return user id .
func (*AccountMapper) MustAccounts ¶
func (a *AccountMapper) MustAccounts(uid string) *user.Accounts
MustAccounts return accounts of give uid.
func (*AccountMapper) MustBindAccount ¶
func (a *AccountMapper) MustBindAccount(uid string, account *user.Account)
MustBindAccount bind account to user. If account exists, error user.ErrAccountBindingExists will raised.
func (*AccountMapper) MustUnbindAccount ¶
func (a *AccountMapper) MustUnbindAccount(uid string, account *user.Account)
MustUnbindAccount unbind account from user.
func (*AccountMapper) Purge ¶
func (a *AccountMapper) Purge(string) error
Purge purge user data cache
func (*AccountMapper) Start ¶
func (a *AccountMapper) Start() error
type AccountModel ¶
type AccountModel struct {
//UID user id.
UID string
//Keyword account keyword.
Keyword string
//Account account name.
Account string
//CreatedTime created timestamp in second.
CreatedTime int64
}
AccountModel account data model
type Config ¶
type Config struct {
Database *db.Config
TableAccount string
TablePassword string
TableToken string
TableUser string
Prefix string
}
func (*Config) ApplyToUser ¶
func (*Config) Execute ¶
func (c *Config) Execute(s *usersystem.UserSystem) error
type PasswordMapper ¶
type PasswordMapper struct {
*modelmapper.ModelMapper
User *User
}
PasswordMapper password mapper
func (*PasswordMapper) Find ¶
func (p *PasswordMapper) Find(uid string) (PasswordModel, error)
Find find password model by userd id. Return any error if raised.
func (*PasswordMapper) InsertOrUpdate ¶
func (p *PasswordMapper) InsertOrUpdate(model *PasswordModel) error
InsertOrUpdate insert or update password model. Return any error if raised.
func (*PasswordMapper) MustUpdatePassword ¶
func (p *PasswordMapper) MustUpdatePassword(uid string, password string)
UpdatePassword update user password.If user password does not exist,new password record will be created.
func (*PasswordMapper) MustVerifyPassword ¶
func (p *PasswordMapper) MustVerifyPassword(uid string, password string) bool
VerifyPassword Verify user password. if user not found,error user.ErrUserNotExists will be raised.
func (*PasswordMapper) PasswordChangeable ¶
func (p *PasswordMapper) PasswordChangeable() bool
PasswordChangeable return password changeable
func (*PasswordMapper) Purge ¶
func (p *PasswordMapper) Purge(string) error
Purge purge user data cache
type PasswordModel ¶
type PasswordModel struct {
//UID user id.
UID string
//HashMethod hash method to verify this password.
HashMethod string
//Salt random salt.
Salt string
//Password hashed password data.
Password []byte
//UpdatedTime updated timestamp in second.
UpdatedTime int64
}
PasswordModel password data model
type Tables ¶
type Tables struct {
AccountMapperName string
PasswordMapperName string
TokenMapperName string
UserMapperName string
}
Tables struct stores table info.
type TokenMapper ¶
type TokenMapper struct {
*modelmapper.ModelMapper
User *User
}
TokenMapper token mapper
func (*TokenMapper) InsertOrUpdate ¶
func (t *TokenMapper) InsertOrUpdate(uid string, token string) error
InsertOrUpdate insert or update user token record.
func (*TokenMapper) MustCurrentTerm ¶
func (t *TokenMapper) MustCurrentTerm(uid string) string
func (*TokenMapper) MustStartNewTerm ¶
func (t *TokenMapper) MustStartNewTerm(uid string) string
type TokenModel ¶
type TokenModel struct {
//UID user id
UID string
//Token current user token
Token string
//UpdatedTime updated timestamp in second.
UpdatedTime string
}
TokenModel token data model
type User ¶
type User struct {
//DB database used.
DB db.Database
//Tables table name info.
Tables Tables
//UIDGenerater string generater for uid
//default value is uuid
UIDGenerater func() (string, error)
//TokenGenerater string generater for usertoken
//default value is timestamp
TokenGenerater func() (string, error)
//SaltGenerater string generater for salt
//default value is 32 byte length random bytes.
SaltGenerater func() (string, error)
//HashMethod hash method which used to generate new salt.
//default value is sha256
HashMethod string
//PasswordKey static key used in password hash generater.
//default value is empty.
//You can change this value after sqluser init.
PasswordKey string
//QueryBuilder sql query builder
QueryBuilder *querybuilder.Builder
}
User main struct of sqluser module.
func (*User) AccountTableName ¶
AccountTableName return actual account database table name.
func (*User) AddTablePrefix ¶
AddTablePrefix add prefix to user table names.
func (*User) PasswordTableName ¶
PasswordTableName return actual password database table name.
func (*User) TokenTableName ¶
TokenTableName return actual token database table name.
func (*User) UserTableName ¶
UserTableName return actual user database table name.
type UserMapper ¶
type UserMapper struct {
*modelmapper.ModelMapper
User *User
}
UserMapper user mapper
func (*UserMapper) IsAvailable ¶
func (u *UserMapper) IsAvailable(userstats status.Status) (bool, error)
IsAvailable check is status available
func (*UserMapper) Label ¶
func (u *UserMapper) Label(userstats status.Status) (string, error)
Label get status label Empty string will be returned if status invalid
func (*UserMapper) MustCreateStatus ¶
func (u *UserMapper) MustCreateStatus(uid string)
func (*UserMapper) MustListUsersByStatus ¶
func (*UserMapper) MustLoadStatus ¶
func (u *UserMapper) MustLoadStatus(uid string) (status.Status, bool)
func (*UserMapper) MustRemoveStatus ¶
func (u *UserMapper) MustRemoveStatus(uid string)
func (*UserMapper) MustUpdateStatus ¶
func (u *UserMapper) MustUpdateStatus(uid string, userstatus status.Status)
func (*UserMapper) Purge ¶
func (u *UserMapper) Purge(uid string) error
func (*UserMapper) Start ¶
func (u *UserMapper) Start() error
func (*UserMapper) Stop ¶
func (u *UserMapper) Stop() error