membership

package
v0.0.0-...-f5f780e Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2013 License: BSD-2-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package membership provide a interface to easy authorization for your web application. This package implements github.com/kidstuff/toys/secure/membership

Index

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 (a *Account) GetConfirmCodes() map[string]string

func (*Account) GetEmail

func (a *Account) GetEmail() string

func (*Account) GetInfomation

func (a *Account) GetInfomation() UserInfo

func (*Account) GetOldPassword

func (a *Account) GetOldPassword() Password

func (*Account) GetPassword

func (a *Account) GetPassword() Password

func (*Account) GetPrivilege

func (a *Account) GetPrivilege() map[string]bool

func (*Account) IsApproved

func (a *Account) IsApproved() bool

type Address

type Address struct {
	Country  string
	State    string
	City     string
	District string
	Street   string
}

type BriefGroup

type BriefGroup struct {
	Id   model.Identifier `bson:"-" datastore:"-"`
	Name string
}

type FormatChecker

type FormatChecker interface {
	PasswordValidate(string) bool
	EmailValidate(string) bool
}

type Group

type Group struct {
	Name      string
	Info      GroupInfo `datastore:",noindex"`
	Privilege map[string]bool
}

func (*Group) GetInfomation

func (g *Group) GetInfomation() GroupInfo

func (*Group) GetName

func (g *Group) GetName() string

func (*Group) GetPrivilege

func (g *Group) GetPrivilege() map[string]bool

type GroupInfo

type GroupInfo struct {
	Description string
}

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 Notificater interface {
	AccountAdded(User) error
	PasswordChanged(User) error
	AccountInfoChanged(User) error
	AccountPrivilegeChanged(User) error
}

type Password

type Password struct {
	Hashed []byte
	Salt   []byte
	InitAt time.Time
}

type Remember

type Remember interface {
	GetId() model.Identifier
	SetId(interface{}) error
	GetToken() string
	SetToken(string)
	GetExpiration() time.Time
	SetExpiration(time.Time)
}

type RememberInfo

type RememberInfo struct {
	Token string
	Exp   time.Time
}

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

type SessionInfo struct {
	At time.Time
}

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 UserInfo

type UserInfo struct {
	FirstName  string
	LastName   string
	MiddleName string
	NickName   string
	BirthDay   time.Time
	JoinDay    time.Time
	Address    []Address
	Phone      []string
}

type UserLister

type UserLister interface {
	At(int) User
	Len() int
	Slice() []User
}

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
}

Directories

Path Synopsis
Package session provide an interface to handle web application session.
Package session provide an interface to handle web application session.

Jump to

Keyboard shortcuts

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