Documentation ¶
Index ¶
- Variables
- func EnsureIndex(db *mgo.Database) error
- func Register(dbsess *mgo.Session, dbname string)
- type LoginState
- type MgoAuthProvider
- type MgoGroupManager
- func (m *MgoGroupManager) AddGroupDetail(name string, info *auth.GroupInfo, pri []string) (*auth.Group, error)
- func (m *MgoGroupManager) Close() error
- func (m *MgoGroupManager) DeleteGroup(id interface{}) error
- func (m *MgoGroupManager) FindAllGroup(offsetId interface{}, limit int) ([]*auth.Group, error)
- func (m *MgoGroupManager) FindGroup(id interface{}) (*auth.Group, error)
- func (m *MgoGroupManager) FindSomeGroup(id ...interface{}) ([]*auth.Group, error)
- func (m *MgoGroupManager) UpdateGroupDetail(id interface{}, info *auth.GroupInfo, pri []string) error
- type MgoUserManager
- func (m *MgoUserManager) AddUser(email, pwd string, app bool) (*auth.User, error)
- func (m *MgoUserManager) AddUserDetail(u *auth.User) (*auth.User, error)
- func (m *MgoUserManager) Can(user *auth.User, do string) bool
- func (m *MgoUserManager) Close() error
- func (m *MgoUserManager) DeleteUser(id interface{}) error
- func (m *MgoUserManager) FindAllUser(offsetId interface{}, limit int) ([]*auth.User, error)
- func (m *MgoUserManager) FindAllUserOnline(offsetId interface{}, limit int) ([]*auth.User, error)
- func (m *MgoUserManager) FindUser(id interface{}) (*auth.User, error)
- func (m *MgoUserManager) FindUserByEmail(email string) (*auth.User, error)
- func (m *MgoUserManager) GetUser(token string) (*auth.User, error)
- func (m *MgoUserManager) GroupManager() auth.GroupManager
- func (m *MgoUserManager) Login(id interface{}, stay time.Duration) (string, error)
- func (m *MgoUserManager) Logout(token string) error
- func (m *MgoUserManager) UpdateUserDetail(u *auth.User) error
- func (m *MgoUserManager) ValidateUser(email, pwd string) (*auth.User, error)
Constants ¶
This section is empty.
Variables ¶
var DefaultProvider = &MgoAuthProvider{}
var (
ErrNoResult = errors.New("mgoauth: no result")
)
var (
ErrNotInit = errors.New("mgoauth: package need to be init")
)
Functions ¶
func EnsureIndex ¶
EnsureIndex builds the index for users data and login state collection.
Types ¶
type LoginState ¶
type MgoAuthProvider ¶
func (*MgoAuthProvider) OpenGroupMngr ¶
func (p *MgoAuthProvider) OpenGroupMngr(*http.Request) (auth.GroupManager, error)
func (*MgoAuthProvider) OpenUserMngr ¶
func (p *MgoAuthProvider) OpenUserMngr(*http.Request) (auth.UserManager, error)
type MgoGroupManager ¶
type MgoGroupManager struct {
GroupColl *mgo.Collection
}
func NewMgoGroupManager ¶
func NewMgoGroupManager(db *mgo.Database) *MgoGroupManager
func (*MgoGroupManager) AddGroupDetail ¶
func (m *MgoGroupManager) AddGroupDetail(name string, info *auth.GroupInfo, pri []string) (*auth.Group, error)
AddGroupDetail adds a group with full detail to database.
func (*MgoGroupManager) Close ¶
func (m *MgoGroupManager) Close() error
func (*MgoGroupManager) DeleteGroup ¶
func (m *MgoGroupManager) DeleteGroup(id interface{}) error
func (*MgoGroupManager) FindAllGroup ¶
func (m *MgoGroupManager) FindAllGroup(offsetId interface{}, limit int) ( []*auth.Group, error)
FindAllGroup finds and return a slice of group. offsetId define which sub-sequence of matching groups to be returned.
func (*MgoGroupManager) FindGroup ¶
func (m *MgoGroupManager) FindGroup(id interface{}) (*auth.Group, error)
FindGroup find the group specific by id.
func (*MgoGroupManager) FindSomeGroup ¶
func (m *MgoGroupManager) FindSomeGroup(id ...interface{}) ( []*auth.Group, error)
FindSomeGroup find and return a slice of group specific by thier id.
func (*MgoGroupManager) UpdateGroupDetail ¶
func (m *MgoGroupManager) UpdateGroupDetail(id interface{}, info *auth.GroupInfo, pri []string) error
UpdateGroupDetail updates group detail specific by id.
type MgoUserManager ¶
type MgoUserManager struct { OnlineThreshold time.Duration UserColl *mgo.Collection LoginColl *mgo.Collection Formater auth.FormatChecker GroupMngr auth.GroupManager }
func NewMgoUserManager ¶
func NewMgoUserManager(db *mgo.Database, groupMngr auth.GroupManager) *MgoUserManager
NewMgoUserManager create new MgoUserManager with UserColl name "mgoauth_user" and LoginColl name "mgoauth_login" with default 5 minutes for OnlineThreshold.
func (*MgoUserManager) AddUser ¶
AddUser will generate user's Id and adds an user to database with email and password; If app is false, the user is waiting to be approved by confirm code. It returns an error describes the first issue encountered, if any.
func (*MgoUserManager) AddUserDetail ¶
AddUserDetail will generate user's Id and adds an user to database; It returns an error describes the first issue encountered, if any.
func (*MgoUserManager) Can ¶
func (m *MgoUserManager) Can(user *auth.User, do string) bool
Can uses GroupManager to determines if user have privilege to do something.
func (*MgoUserManager) Close ¶
func (m *MgoUserManager) Close() error
func (*MgoUserManager) DeleteUser ¶
func (m *MgoUserManager) DeleteUser(id interface{}) error
DeleteUserByEmail deletes an user from database base on the given id; It returns an error describes the first issue encountered, if any.
func (*MgoUserManager) FindAllUser ¶
func (m *MgoUserManager) FindAllUser(offsetId interface{}, limit int) ( []*auth.User, error)
FindAllUser finds and return a slice of user. offsetId, limit define which sub-sequence of matching users to return. Limit take an number of user per page; offsetId take the Id of the last user of the previous page.
func (*MgoUserManager) FindAllUserOnline ¶
func (m *MgoUserManager) FindAllUserOnline(offsetId interface{}, limit int) ( []*auth.User, error)
FindAllUserOline finds and return a slice of current Loged user. See FindAllUser for the usage.
func (*MgoUserManager) FindUser ¶
func (m *MgoUserManager) FindUser(id interface{}) (*auth.User, error)
FindUser finds the user with the given id; Its returns an ErrNotFound if the user's id was not found.
func (*MgoUserManager) FindUserByEmail ¶
func (m *MgoUserManager) FindUserByEmail(email string) (*auth.User, error)
FindUserByEmail like FindUser but receive an email
func (*MgoUserManager) GetUser ¶
func (m *MgoUserManager) GetUser(token string) (*auth.User, error)
GetUser gets the infomations and update the LastActivity of the current Loged user; It returns an error describes the first issue encountered, if any.
func (*MgoUserManager) GroupManager ¶
func (m *MgoUserManager) GroupManager() auth.GroupManager
GroupManager returns the GroupManager.
func (*MgoUserManager) Login ¶
func (m *MgoUserManager) Login(id interface{}, stay time.Duration) (string, error)
Login logs user in. IF stay lester than default OnlineThreshold user will stay in OnlineThreshold.
func (*MgoUserManager) Logout ¶
func (m *MgoUserManager) Logout(token string) error
Logout logs the current user out.
func (*MgoUserManager) UpdateUserDetail ¶
func (m *MgoUserManager) UpdateUserDetail(u *auth.User) error
UpdateUserDetail update user infomation specific by Id and Email field. It returns an error describes the first issue encountered, if any.
func (*MgoUserManager) ValidateUser ¶
func (m *MgoUserManager) ValidateUser(email, pwd string) (*auth.User, error)
ValidateUser validate user email and password. It returns the user infomations if the email and password is correct.