Documentation ¶
Index ¶
- Constants
- Variables
- func IsAvaliable(s *Status) bool
- type Accounts
- type AccountsProvider
- type AccountsStore
- type Authorizer
- type ContextType
- type Directive
- type DirectiveFactory
- type Members
- func (m *Members) Data(field string) datastore.Store
- func (m *Members) LoadAccount(keys ...string) (*AccountsStore, error)
- func (m *Members) LoadData(field string, keys ...string) (datastore.Store, error)
- func (m *Members) LoadProfiles(keys ...string) (*ProfilesStore, error)
- func (m *Members) LoadRoles(keys ...string) (*RolesStore, error)
- func (m *Members) LoadStatus(keys ...string) (*StatusStore, error)
- func (m *Members) LoadTokens(keys ...string) (*TokensStore, error)
- func (m *Members) Status(key string) (*Status, error)
- type Option
- type OptionFunc
- type PasswordProvider
- type Profiles
- type ProfilesProvider
- type ProfilesStore
- type Roles
- type RolesProvider
- type RolesStore
- type Service
- func (s *Service) Accounts() *ServiceAccounts
- func (s *Service) AuthorizeMiddleware(rs protecter.PolicyLoader, unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (s *Service) Authorizer(rs protecter.PolicyLoader) httpuser.Authorizer
- func (s *Service) BannedMiddleware() func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (s *Service) Data() *ServiceData
- func (s *Service) GetMembersFromRequest(r *http.Request) (members *Members)
- func (s *Service) IdentifyRequest(r *http.Request) (uid string, err error)
- func (s *Service) Init(option Option) error
- func (s *Service) Login(w http.ResponseWriter, r *http.Request, id string) error
- func (s *Service) LoginRequiredMiddleware(unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (s *Service) Logout(w http.ResponseWriter, r *http.Request) error
- func (s *Service) LogoutMiddleware() func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (s *Service) MemberTokenField() *session.Field
- func (s *Service) NewAccount(keyword string, account string) (*user.Account, error)
- func (s *Service) NewMembers() *Members
- func (s *Service) Password() *ServicePassword
- func (s *Service) Profiles() *ServiceProfiles
- func (s *Service) RegisterAccountProvider(keyword string, t user.AccountProvider)
- func (s *Service) RegisterData(key string, p *datastore.DataSource) error
- func (s *Service) RequestProfiles(r *http.Request) (*profile.Profile, error)
- func (s *Service) Reset()
- func (s *Service) Roles() *ServiceRole
- func (s *Service) RolesAuthorizeMiddleware(ruleNames ...string) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
- func (s *Service) Status() *ServiceStatus
- func (s *Service) Token() *ServiceToken
- func (s *Service) UIDField() *session.Field
- type ServiceAccounts
- func (s *ServiceAccounts) AccountToUID(account *user.Account) (uid string, err error)
- func (s *ServiceAccounts) AccountToUIDOrRegister(account *user.Account) (uid string, registerd bool, err error)
- func (s *ServiceAccounts) BindAccount(uid string, account *user.Account) error
- func (s *ServiceAccounts) Cache() cache.Cacheable
- func (s *ServiceAccounts) Clean(uid string) error
- func (s *ServiceAccounts) Load(accounts datastore.Store, keys ...string) error
- func (s *ServiceAccounts) Register(account *user.Account) (uid string, err error)
- func (s *ServiceAccounts) UnbindAccount(uid string, account *user.Account) error
- type ServiceData
- type ServicePassword
- type ServiceProfiles
- type ServiceRole
- type ServiceStatus
- type ServiceToken
- type Status
- type StatusMap
- type StatusProvider
- type StatusStore
- type TokenProvider
- type Tokens
- type TokensStore
Constants ¶
const DefaultSessionMemberTokenFieldName = "herb-member-token"
DefaultSessionMemberTokenFieldName default member token session field name when create member service.
const DefaultSessionUIDFieldName = "herb-member-uid"
DefaultSessionUIDFieldName default user id session field name when create member service.
const StatusBanned = Status(1)
StatusBanned user status banned
const StatusExpired = Status(4)
StatusExpired user status expried
const StatusNormal = Status(0)
StatusNormal user status normal
const StatusPending = Status(3)
StatusPending user status pending
const StatusRevoked = Status(2)
StatusRevoked user status revoked
Variables ¶
var DefaultContextName = ContextType("members")
DefaultContextName default member context name.
var ErrAccountKeywordNotRegistered = errors.New("account keyword not regietered")
ErrAccountKeywordNotRegistered errors rasied when account keyword not regietered.
var ErrAccountRegisterExists = errors.New("account registered exists")
ErrAccountRegisterExists errors rasied when registered account ecists.
var ErrFeatureNotSupported = errors.New("feature not supported")
ErrFeatureNotSupported errors rasied when feature not supported by provider.
var ErrPasswordNotChangeable = errors.New("password not changeable")
ErrPasswordNotChangeable errors raised when password provider not support change password.
var ErrRegisteredDataNotMap = errors.New("registered user data is not a map")
ErrRegisteredDataNotMap errors rasied when registered user data struct is not a map struct.
var ErrStatusNotSupport = errors.New("user status not support")
ErrStatusNotSupport errors rasied when user status is not support by provider.
var ErrUserBanned = errors.New("user banned")
ErrUserBanned errors rasied when user status is banned.
var ErrUserNotFound = errors.New("user not found")
ErrUserNotFound errors rasied when user is not found.
var StatusMapAll = map[Status]bool{ StatusNormal: true, StatusBanned: true, StatusRevoked: true, StatusPending: true, StatusExpired: true, }
var StatusMapMin = map[Status]bool{ StatusNormal: true, StatusBanned: true, }
Functions ¶
func IsAvaliable ¶
IsAvaliable check if user status is normal status.
Types ¶
type AccountsProvider ¶
type AccountsProvider interface { //Accounts return account map of given uid list. //Return account map and any error if raised. Accounts(uid ...string) (*Accounts, error) //AccountToUID query uid by user account. //Return user id and any error if raised. //Return empty string as userid if account not found. AccountToUID(account *user.Account) (uid string, err error) //Register create new user with given account. //Return created user id and any error if raised. //Privoder should return ErrAccountRegisterExists if account is used. Register(account *user.Account) (uid string, err error) //AccountToUIDOrRegister query uid by user account.Register user if account not found. //Return user id and any error if raised. AccountToUIDOrRegister(account *user.Account) (uid string, registerd bool, err error) //BindAccount bind account to user. //Return any error if raised. //If account exists,user.ErrAccountBindingExists should be rasied. BindAccount(uid string, account *user.Account) error //UnbindAccount unbind account from user. //Return any error if raised. //If account not exists,user.ErrAccountUnbindingNotExists should be rasied. UnbindAccount(uid string, account *user.Account) error }
AccountsProvider member account provider interface
type AccountsStore ¶
type AccountsStore struct {
*datastore.SyncMapStore
}
AccountsStore accounts data store
func NewAccountsStore ¶
func NewAccountsStore() *AccountsStore
NewAccountsStore create new account data store
type Authorizer ¶
type Authorizer struct { Service *Service PolicyLoader protecter.PolicyLoader }
Authorizer comonets to Authorize http request. Should be created by Service.Authorize
type DirectiveFactory ¶
DirectiveFactory member Directive create factory.
type Members ¶
type Members struct { Service *Service Accounts *AccountsStore StatusStore *StatusStore Tokens *TokensStore Roles *RolesStore Profiles *ProfilesStore Dataset map[string]datastore.Store }
Members members stand for cached user data.
func NewMembers ¶
NewMembers return empty members with given service.
func (*Members) LoadAccount ¶
func (m *Members) LoadAccount(keys ...string) (*AccountsStore, error)
LoadAccount load accounts for users. loaded tokens will stored in members Accounts field. Return Accounts and any error if rased.
func (*Members) LoadData ¶
LoadData load named data for users. loaded datas will stored in members Dataset field. Return datas and any error if rased.
func (*Members) LoadProfiles ¶
func (m *Members) LoadProfiles(keys ...string) (*ProfilesStore, error)
LoadProfiles load profiles for users. loaded profiles will stored in members Profiles field. Return Profiles and any error if rased.
func (*Members) LoadRoles ¶
func (m *Members) LoadRoles(keys ...string) (*RolesStore, error)
LoadRoles load roles for users. loaded roles will stored in members Roles field. Return Roles and any error if rased.
func (*Members) LoadStatus ¶
func (m *Members) LoadStatus(keys ...string) (*StatusStore, error)
LoadStatus load banned status for users. loaded status will stored in members StatusStore field. Return status map and any error if rased.
func (*Members) LoadTokens ¶
func (m *Members) LoadTokens(keys ...string) (*TokensStore, error)
LoadTokens load tokens for users. loaded tokens will stored in members Tokens field. Return Tokens and any error if rased.
type OptionFunc ¶
OptionFunc member service option function interface.
func OptionCommon ¶
func OptionCommon(store *session.Store) OptionFunc
OptionCommon common member service option function with give session store.
func OptionSubCache ¶
func OptionSubCache(store *session.Store, c cache.Cacheable) OptionFunc
OptionSubCache option use sub cache node of give cache as all modules's cache.
func (OptionFunc) ApplyTo ¶
func (i OptionFunc) ApplyTo(s *Service) error
ApplyTo apply option function to service.
type PasswordProvider ¶
type PasswordProvider interface { VerifyPassword(uid string, password string) (bool, error) //PasswordChangeable return password changeable PasswordChangeable() bool //UpdatePassword update user password //Return any error if raised UpdatePassword(uid string, password string) error }
PasswordProvider member password provider interface
type ProfilesProvider ¶
type ProfilesProvider interface { Profiles(uid ...string) (*Profiles, error) UpdateProfile(uid string, profile *profile.Profile) error }
ProfilesProvider member role provider interface
type ProfilesStore ¶
type ProfilesStore struct {
*datastore.SyncMapStore
}
ProfilesStore user profiles data store
func NewProfilesStore ¶
func NewProfilesStore() *ProfilesStore
NewProfilesStore create new user profiles data store
type RolesProvider ¶
RolesProvider member role provider interface
type RolesStore ¶
type RolesStore struct {
*datastore.SyncMapStore
}
RolesStore user roles data store
func NewRolesStore ¶
func NewRolesStore() *RolesStore
NewRolesStore create new user rolees data store
type Service ¶
type Service struct { //SessionStore session store which stores member data. SessionStore *session.Store //SessionUIDFieldName session field which stores user id. SessionUIDFieldName string //SessionMemberFieldName session field which stores member token. SessionMemberFieldName string //ContextName context name stores members data. ContextName ContextType //BannedProvider user banned status provider. //DON'T use this provider directly,use Service.Banned() instead. StatusProvider StatusProvider //BannedCache data stores banned status. StatusCache cache.Cacheable //AccountsProvider user accounts provider. //DON'T use this provider directly,use Service.Accounts() instead. AccountsProvider AccountsProvider //AccountsCache data stores user accounts. AccountsCache cache.Cacheable //TokenProvider user token provider. //DON'T use this provider directly,use Service.Tokens() instead. TokenProvider TokenProvider //TokenCache data stores user tokens. TokenCache cache.Cacheable //PasswordProvider user password provider. //DON'T use this provider directly,use Service.Password() instead. PasswordProvider PasswordProvider //RoleProvider user roles provider. //DON'T use this provider directly,use Service.Roles() instead. RoleProvider RolesProvider //RoleCache data stores user roles. RoleCache cache.Cacheable //DataProviders user data provider. //A map of registered data map type. DataProviders map[string]*datastore.DataSource //DataCache data stores user dataset. DataCache cache.Cacheable //User Profiles Providers ProfilesProviders []ProfilesProvider //AccountProviders registered account provider map. AccountProviders map[string]user.AccountProvider }
Service member service main interafce.
func (*Service) Accounts ¶
func (s *Service) Accounts() *ServiceAccounts
Accounts return Accounts module.
func (*Service) AuthorizeMiddleware ¶
func (s *Service) AuthorizeMiddleware(rs protecter.PolicyLoader, unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
AuthorizeMiddleware return Authorize Middleware with special rule provider. Middleware will check user banned status if banned status provider is installed.
func (*Service) Authorizer ¶
func (s *Service) Authorizer(rs protecter.PolicyLoader) httpuser.Authorizer
Authorizer create Authorizer with given rule provider.
func (*Service) BannedMiddleware ¶
func (s *Service) BannedMiddleware() func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
BannedMiddleware return Authorize Middleware check only if user is banned
func (*Service) GetMembersFromRequest ¶
GetMembersFromRequest get members data in http request context. Create new members data and bind to context if not exist. Return members data.
func (*Service) IdentifyRequest ¶
IdentifyRequest Identify user in http request. Return user id and any error raised. If user is not logged in,returned user id will by empty string.
func (*Service) LoginRequiredMiddleware ¶
func (s *Service) LoginRequiredMiddleware(unauthorizedAction http.HandlerFunc) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
LoginRequiredMiddleware return login requred middleware with given unauthorizedAction.
func (*Service) LogoutMiddleware ¶
func (s *Service) LogoutMiddleware() func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
LogoutMiddleware return logout middleware.
func (*Service) MemberTokenField ¶
MemberTokenField return member token session field
func (*Service) NewAccount ¶
NewAccount create new account by given registered keyword and account name. Return created user account and any error if raised. Return ErrAccountKeywordNotRegistered if account keyword is not registered by Service.RegisterAccountType .
func (*Service) NewMembers ¶
NewMembers return new members data.
func (*Service) Password ¶
func (s *Service) Password() *ServicePassword
Password return Password modules.
func (*Service) Profiles ¶
func (s *Service) Profiles() *ServiceProfiles
Profiles return profiles modules.
func (*Service) RegisterAccountProvider ¶
func (s *Service) RegisterAccountProvider(keyword string, t user.AccountProvider)
RegisterAccountProvider register account provider as keyword.
func (*Service) RegisterData ¶
func (s *Service) RegisterData(key string, p *datastore.DataSource) error
RegisterData register data type as named data field. data type should implement DataProvider interface so that data module can create and load user data. Return any error if raised. DEPRECATED
func (*Service) RequestProfiles ¶
func (*Service) RolesAuthorizeMiddleware ¶
func (s *Service) RolesAuthorizeMiddleware(ruleNames ...string) func(w http.ResponseWriter, r *http.Request, next http.HandlerFunc)
RolesAuthorizeMiddleware return Authorize Middleware with roles as rule provider. Middleware will check user banned status if banned status provider is installed.
type ServiceAccounts ¶
type ServiceAccounts struct {
// contains filtered or unexported fields
}
ServiceAccounts Member accounts module.
func (*ServiceAccounts) AccountToUID ¶
func (s *ServiceAccounts) AccountToUID(account *user.Account) (uid string, err error)
AccountToUID query uid by user account. Return user id and any error if raised. Return empty string as userid if account not found.
func (*ServiceAccounts) AccountToUIDOrRegister ¶
func (s *ServiceAccounts) AccountToUIDOrRegister(account *user.Account) (uid string, registerd bool, err error)
AccountToUIDOrRegister query uid by user account.Register user if account not found. Return user id ,whether registered and any error if raised.
func (*ServiceAccounts) BindAccount ¶
func (s *ServiceAccounts) BindAccount(uid string, account *user.Account) error
BindAccount bind account to user. user account cache will be cleand. Return any error if raised. If account exists,user.ErrAccountBindingExists should be rasied.
func (*ServiceAccounts) Cache ¶
func (s *ServiceAccounts) Cache() cache.Cacheable
Cache Return member accounts cache.
func (*ServiceAccounts) Clean ¶
func (s *ServiceAccounts) Clean(uid string) error
Clean clean accounts cache by uid. Return any error if raised.
func (*ServiceAccounts) Load ¶
func (s *ServiceAccounts) Load(accounts datastore.Store, keys ...string) error
Load load and cache accounts from provider. Return any error if raised.
func (*ServiceAccounts) Register ¶
func (s *ServiceAccounts) Register(account *user.Account) (uid string, err error)
Register create new user with given account. Return created user id and any error if raised.
func (*ServiceAccounts) UnbindAccount ¶
func (s *ServiceAccounts) UnbindAccount(uid string, account *user.Account) error
UnbindAccount unbind account from user. user account cache will be cleand. Return any error if raised. If account not exists,user.ErrAccountUnbindingNotExists should be rasied.
type ServiceData ¶
type ServiceData struct {
// contains filtered or unexported fields
}
ServiceData member user data module. DEPRECATED
func (*ServiceData) Cache ¶
func (s *ServiceData) Cache(field string) cache.Cacheable
Cache Return member user data cache. DEPRECATED
type ServicePassword ¶
type ServicePassword struct {
// contains filtered or unexported fields
}
ServicePassword Member password module.
func (*ServicePassword) PasswordChangeable ¶
func (s *ServicePassword) PasswordChangeable() bool
PasswordChangeable return password changeable
func (*ServicePassword) UpdatePassword ¶
func (s *ServicePassword) UpdatePassword(uid string, password string) error
UpdatePassword update user password Return any error if raised
func (*ServicePassword) VerifyPassword ¶
func (s *ServicePassword) VerifyPassword(uid string, password string) (bool, error)
VerifyPassword Verify user password. Return verify result and any error if raised
type ServiceProfiles ¶
type ServiceProfiles struct {
// contains filtered or unexported fields
}
ServiceProfiles member profile module.
func (*ServiceProfiles) Load ¶
func (s *ServiceProfiles) Load(store datastore.Store, keys ...string) error
Load load user profiles from provider. Return any error if raised.
func (*ServiceProfiles) UpdateProfile ¶
func (s *ServiceProfiles) UpdateProfile(uid string, profile *profile.Profile) error
type ServiceRole ¶
type ServiceRole struct {
// contains filtered or unexported fields
}
ServiceRole member role module.
func (*ServiceRole) Cache ¶
func (s *ServiceRole) Cache() cache.Cacheable
Cache Return member role cache.
func (*ServiceRole) Clean ¶
func (s *ServiceRole) Clean(uid string) error
Clean clean role cache by uid.
type ServiceStatus ¶
type ServiceStatus struct {
// contains filtered or unexported fields
}
ServiceStatus Member status module.
func (*ServiceStatus) Cache ¶
func (s *ServiceStatus) Cache() cache.Cacheable
Cache Return member status cache.
func (*ServiceStatus) Clean ¶
func (s *ServiceStatus) Clean(uid string) error
Clean clean status cache by uid.
type ServiceToken ¶
type ServiceToken struct {
// contains filtered or unexported fields
}
ServiceToken member token module.
func (*ServiceToken) Cache ¶
func (s *ServiceToken) Cache() cache.Cacheable
Cache Return member token cache.
func (*ServiceToken) Clean ¶
func (s *ServiceToken) Clean(uid string) error
Clean clean token cache by uid.
type Status ¶
type Status int
Status user status type
func (*Status) IsAvaliable ¶
IsAvaliable check if user status is normal status.
type StatusProvider ¶
type StatusProvider interface { //Statuses return status map of given uid list. //Return status map and any error if raised. Statuses(uid ...string) (StatusMap, error) //SetStatus set user status. //Return any error if raised. SetStatus(uid string, status Status) error //SupportedStatus return supported status map SupportedStatus() map[Status]bool }
StatusProvider member status provider interface
type StatusStore ¶
type StatusStore struct {
*datastore.SyncMapStore
}
StatusStore user status data store
func NewStatusStore ¶
func NewStatusStore() *StatusStore
NewStatusStore create new status data store
func (*StatusStore) Get ¶
func (s *StatusStore) Get(uid string) *Status
Get get user status by given user id
type TokenProvider ¶
type TokenProvider interface { Tokens(uid ...string) (Tokens, error) Revoke(uid string) (string, error) }
TokenProvider member token provider interface
type TokensStore ¶
type TokensStore struct {
*datastore.SyncMapStore
}
TokensStore user token data store
func NewTokensStore ¶
func NewTokensStore() *TokensStore
NewTokensStore create new user token data store.
func (*TokensStore) Get ¶
func (s *TokensStore) Get(uid string) string
Get get user token by given user id