mgoauth

package
v0.0.0-...-8af4378 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2014 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultProvider = &MgoAuthProvider{}
View Source
var (
	ErrNoResult = errors.New("mgoauth: no result")
)
View Source
var (
	ErrNotInit = errors.New("mgoauth: package need to be init")
)

Functions

func EnsureIndex

func EnsureIndex(db *mgo.Database) error

EnsureIndex builds the index for users data and login state collection.

func Register

func Register(dbsess *mgo.Session, dbname string)

Types

type LoginState

type LoginState struct {
	ExpiredOn time.Time     `bson:"ExpiredOn"`
	UserId    bson.ObjectId `bson:"UserId"`
	Token     string        `bson:"_id"`
}

type MgoAuthProvider

type MgoAuthProvider struct {
	DBSess *mgo.Session
	DBName string
}

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

func (m *MgoUserManager) AddUser(email, pwd string, app bool) (*auth.User,
	error)

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

func (m *MgoUserManager) AddUserDetail(u *auth.User) (*auth.User, error)

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.

Jump to

Keyboard shortcuts

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