Documentation
¶
Overview ¶
Package membership provide a interface to easy authorization for your web application. This package implements github.com/kidstuff/toys/secure/membership
Index ¶
- Variables
- type Account
- func (a *Account) GetConfirmCodes() map[string]string
- func (a *Account) GetEmail() string
- func (a *Account) GetInfomation() UserInfo
- func (a *Account) GetOldPassword() Password
- func (a *Account) GetPassword() Password
- func (a *Account) GetPrivilege() map[string]bool
- func (a *Account) IsApproved() bool
- type Address
- type BriefGroup
- type FormatChecker
- type Group
- type GroupInfo
- type GroupManager
- type Grouper
- type Notificater
- type Password
- type Remember
- type RememberInfo
- type SMTPNotificater
- type SessionInfo
- type Sessioner
- type SimpleChecker
- type User
- type UserInfo
- type UserLister
- type UserManager
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrInvalidId error = errors.New("membership: invalid id") ErrInvalidEmail error = errors.New("membership: invalid email address") ErrDuplicateEmail error = errors.New("membership: duplicate email address") ErrInvalidPassword error = errors.New("membership: invalid password") )
View Source
var (
ErrDuplicateName = errors.New("membership: duplicate Group Name")
)
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct { Email string OldPwd Password Pwd Password LastActivity time.Time Info UserInfo `datastore:",noindex"` Privilege map[string]bool Approved bool ConfirmCodes map[string]string }
func (*Account) GetConfirmCodes ¶
func (*Account) GetInfomation ¶
func (*Account) GetOldPassword ¶
func (*Account) GetPassword ¶
func (*Account) GetPrivilege ¶
func (*Account) IsApproved ¶
type BriefGroup ¶
type BriefGroup struct { Id model.Identifier `bson:"-" datastore:"-"` Name string }
type FormatChecker ¶
type GroupManager ¶
type GroupManager interface { AddGroupDetail(name string, info GroupInfo, pri map[string]bool) (Grouper, error) UpdateInfo(id model.Identifier, info GroupInfo) error UpdatePrivilege(id model.Identifier, pri map[string]bool) error FindGroup(id model.Identifier) (Grouper, error) FindGroupByName(name string) (Grouper, error) FindAllGroup(offsetId model.Identifier, limit int) ([]Grouper, error) }
type Grouper ¶
type Grouper interface { GetId() model.Identifier SetId(model.Identifier) error GetName() string GetInfomation() GroupInfo GetPrivilege() map[string]bool }
type Notificater ¶
type RememberInfo ¶
func (*RememberInfo) GetExpiration ¶
func (r *RememberInfo) GetExpiration() time.Time
func (*RememberInfo) GetToken ¶
func (r *RememberInfo) GetToken() string
func (*RememberInfo) SetExpiration ¶
func (r *RememberInfo) SetExpiration(t time.Time)
func (*RememberInfo) SetToken ¶
func (r *RememberInfo) SetToken(token string)
type SMTPNotificater ¶
type SMTPNotificater struct { Auth smtp.Auth // Outgoing Mail (SMTP) Server Address, eg: smtp.gmail.com Addr string // Port of SMTP Server, eg: 587 Port int // Email use to send, eg: no-reply@gmail.com Email string // contains filtered or unexported fields }
func NewSMTPNotificater ¶
func NewSMTPNotificater(email, pass, addr string, port int) *SMTPNotificater
func (*SMTPNotificater) AccountAdded ¶
func (n *SMTPNotificater) AccountAdded(user User) error
func (*SMTPNotificater) AccountInfoChanged ¶
func (n *SMTPNotificater) AccountInfoChanged(user User) error
func (*SMTPNotificater) AccountPrivilegeChanged ¶
func (n *SMTPNotificater) AccountPrivilegeChanged(user User) error
func (*SMTPNotificater) PasswordChanged ¶
func (n *SMTPNotificater) PasswordChanged(user User) error
type SessionInfo ¶
func (*SessionInfo) GetCreateTime ¶
func (s *SessionInfo) GetCreateTime() time.Time
func (*SessionInfo) SetCreateTime ¶
func (s *SessionInfo) SetCreateTime(t time.Time)
type Sessioner ¶
type Sessioner interface { GetId() model.Identifier SetId(model.Identifier) error GetCreateTime() time.Time SetCreateTime(time.Time) }
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 interface { GetId() model.Identifier SetId(model.Identifier) error GetEmail() string GetPassword() Password GetOldPassword() Password GetInfomation() UserInfo GetPrivilege() map[string]bool IsApproved() bool GetConfirmCodes() map[string]string GetBriefGroups() []BriefGroup }
type UserManager ¶
type UserManager interface { SetPath(p string) SetDomain(d string) SetGroupManager(GroupManager) GroupManager() GroupManager // SetOnlineThreshold sets the online threshold time, if t <= 0, the Login // state will last until the session expired. SetOnlineThreshold(t time.Duration) // SetHashFunc sets the hash.Hash which will be use for password hasing SetHashFunc(h hash.Hash) // SetNotificater sets the Notificater which will be use for sending // notification to user when account added or password changed. SetNotificater(n Notificater) // SetFormatChecker sets a FormatChecker for validate email/password SetFormatChecker(c FormatChecker) // AddUser adds an user to database with email and password; // if notif is true, a NewAccount notification will be send to user by the // Notificater. If app is false, the user is waiting to be approved. // It returns an error describes the first issue encountered, if any. AddUser(email, pwd string, notif, app bool) (User, error) // AddUserInfo adds an user to database; // if notif is true, a NewAccount notification will be send to user by the // Notificater. If app is false, the user is waiting to be approved. // It returns an error describes the first issue encountered, if any. AddUserDetail(email, pwd string, info UserInfo, pri map[string]bool, notif, app bool) (User, error) // UpdateInfo changes information of user specify by id and send a // notification if need. It returns error if any. UpdateInfo(id model.Identifier, info UserInfo, notif bool) error // UpdatePrivilege changes privilege of user specify by id and send a // notification if need. It returns error if any. UpdatePrivilege(id model.Identifier, pri map[string]bool, notif bool) error // ChangePassword changes passowrd of user specify by id and send a // notification if need. It returns error if any. ChangePassword(id model.Identifier, password string, notif bool) error // DeleteUserByEmail deletes an user from database base on the given id; // It returns an error describes the first issue encountered, if any. DeleteUser(id model.Identifier) 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. GetUser() (User, error) // FindUser finds the user with the given id; // Its returns an ErrNotFound if the user's id was not found. FindUser(id model.Identifier) (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 model.Identifier, limit int) ([]User, error) // FindAllUserOline finds and return a slice of current Loged user. // See FindAllUser for the usage. FindAllUserOnline(offsetId model.Identifier, limit int) ([]User, error) // CountUserOnline counts the number of user current Loged. // It counts the user that LastActivity+OnlineThreshold<Now. CountUserOnline() int // ValidateUser validate user email and password. // It returns the user infomations if the email and password is correct. ValidateUser(email string, password string) (User, error) // Login logs user in by using a session that store user id. // Remember take a number of second to keep the user Login state. // Developer must call LoginUser before send any output to browser. Login(id model.Identifier, remember int) error // Logout logs the current user out. Logout() error // ValidConfirmCode valid the code for specific key of the user specify by id. // Re-generate or delete code for that key if need. ValidConfirmCode(id model.Identifier, key, code string, regen, del bool) (bool, error) // GeneratePassword caculation a membership.Password if the given password. // If password is empty, GeneratePassword will generate everything. GeneratePassword(password string) Password // Can uses GroupManager to determines if user have privilege to do something. Can(user User, do string) bool }
Source Files
¶
Click to show internal directories.
Click to hide internal directories.