Documentation ¶
Overview ¶
Package auth provide a interface to easy authorization for your web application.
Index ¶
- Variables
- func OAuthHandleWrapper(handler http.HandlerFunc, groups []string, pri []string) http.HandlerFunc
- func OAuthOwnerPrivilegeWrapper(handler http.HandlerFunc, userIdField string) http.HandlerFunc
- func Register(name string, p AuthProvider) error
- type Address
- type AuthProvider
- type BriefGroup
- type FormatChecker
- type Group
- type GroupInfo
- type GroupManager
- type Password
- type SimpleChecker
- type User
- type UserInfo
- type UserManager
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidId = errors.New("auth: invalid id") ErrInvalidEmail = errors.New("auth: invalid email address") ErrDuplicateEmail = errors.New("auth: duplicate email address") ErrInvalidPassword = errors.New("auth: invalid password") ErrNotLogged = errors.New("auth: no login user found") ErrNoProvider = errors.New("auth: no provider found") )
View Source
var (
ErrDuplicateName = errors.New("auth: duplicate Group Name")
)
Functions ¶
func OAuthHandleWrapper ¶
func OAuthHandleWrapper(handler http.HandlerFunc, groups []string, pri []string) http.HandlerFunc
func OAuthOwnerPrivilegeWrapper ¶
func OAuthOwnerPrivilegeWrapper(handler http.HandlerFunc, userIdField string) http.HandlerFunc
func Register ¶
func Register(name string, p AuthProvider) error
Types ¶
type AuthProvider ¶
type AuthProvider interface { OpenUserMngr(*http.Request) (UserManager, error) OpenGroupMngr(*http.Request) (GroupManager, error) }
func GetProvider ¶
func GetProvider(name string) (AuthProvider, error)
func Provider ¶
func Provider() AuthProvider
Provider returns the last provider added. It will panic if there's no one.
type BriefGroup ¶
type BriefGroup struct { Id interface{} `bson:"_id"` Name string `bson:"Name"` }
type FormatChecker ¶
type Group ¶
type Group struct { BriefGroup `bson:"BriefGroup,inline"` Info GroupInfo `bson:"Info" datastore:",noindex"` Privilege []string `bson:"Privilege"` }
type GroupManager ¶
type GroupManager interface { // AddGroupDetail adds a group with full detail to database. AddGroupDetail(name string, info *GroupInfo, pri []string) (*Group, error) // UpdateGroupDetail updates group detail specific by id. UpdateGroupDetail(id interface{}, info *GroupInfo, pri []string) error // FindGroup find the group specific by id. FindGroup(id interface{}) (*Group, error) // FindSomeGroup find and return a slice of group specific by thier id. FindSomeGroup(id ...interface{}) ([]*Group, error) // FindAllGroup finds and return a slice of group. offsetId define which // sub-sequence of matching groups to be returned. FindAllGroup(offsetId interface{}, limit int) ([]*Group, error) // DeleteGroup deletes a group from database base on the given id; // It returns an error describes the first issue encountered, if any. DeleteGroup(id interface{}) error // Close clean the resources used by the manager if need. Close() error }
type Password ¶
type SimpleChecker ¶
type SimpleChecker struct {
// contains filtered or unexported fields
}
func NewSimpleChecker ¶
func NewSimpleChecker(pwdlen int) (*SimpleChecker, error)
func (*SimpleChecker) EmailValidate ¶
func (c *SimpleChecker) EmailValidate(email string) bool
func (*SimpleChecker) PasswordValidate ¶
func (c *SimpleChecker) PasswordValidate(pwd string) bool
type User ¶
type User struct { Id interface{} `bson:"_id" datastore:"-"` Email string `bson:"Email"` OldPwd []Password `bson:"OldPwd" json:",omitempty"` Pwd Password `bson:"Pwd" json:",omitempty"` LastActivity time.Time `bson:"LastActivity` Info UserInfo `bson:"Info" datastore:",noindex" json:",omitempty"` Privilege []string `bson:"Privilege"` Approved bool `bson:"Approved"` ConfirmCodes map[string]string `bson:"ConfirmCodes" datastore:"-" json:",omitempty"` BriefGroups []BriefGroup `bson:"BriefGroups"` }
func (*User) ChangePassword ¶
func (*User) ComparePassword ¶
type UserInfo ¶
type UserInfo struct { FirstName string `bson:"FirstName"` LastName string `bson:"LastName"` MiddleName string `bson:"MiddleName"` NickName string `bson:"NickName"` BirthDay time.Time `bson:"BirthDay"` JoinDay time.Time `bson:"JoinDay"` Address []Address `bson:"Address"` Phone []string `bson:"Phone"` }
type UserManager ¶
type UserManager interface { // GroupManager returns the GroupManager. GroupManager() GroupManager // AddUser adds an user to database with email and password; // If app is false, the user is waiting to be approved. // Implement of this method should valid email, pwd and make sure the user // email are unique. // It returns an error describes the first issue encountered, if any. AddUser(email, pwd string, app bool) (*User, error) // AddUserDetail add a User with full detail to database. // Implement of this method should valid email, pwd and make sure the user // email are unique. // It returns an error describes the first issue encountered, if any. AddUserDetail(*User) (*User, error) // UpdateUserDetail changes detail of the User. // It returns an error describes the first issue encountered, if any. UpdateUserDetail(*User) error // DeleteUser deletes an user from database base on the given id; // It returns an error describes the first issue encountered, if any. DeleteUser(id interface{}) error // FindUser finds the user with the given id; // Its returns an ErrNotFound if the user's id was not found. FindUser(id interface{}) (*User, error) // FindUserByEmail like FindUser but receive an email FindUserByEmail(email string) (*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. FindAllUser(offsetId interface{}, limit int) ([]*User, error) // FindAllUserOline finds and return a slice of current Loged user. // See FindAllUser for the usage. FindAllUserOnline(offsetId interface{}, limit int) ([]*User, error) // ValidateUser validate user base on the current request. // It returns the user infomations if the email and password is correct. ValidateUser(email, pwd string) (*User, error) // GetUser gets the infomations and update the LastActivity of the current // loged user by the token (given by Login method); // It returns an error describes the first issue encountered, if any. GetUser(token string) (*User, error) // Login logs user in by given user id. // Stay is the duration to keep the user Login state. // It returns a token string, use the token to keep track on the user with // GetUser or Logout. Login(id interface{}, stay time.Duration) (string, error) // Logout logs the current user out. Logout(token string) error // Can uses GroupManager to determines if user have privilege to do something. Can(user *User, do string) bool // Close clean the resources used by the manager if need. Close() error }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.