membership

package
v0.0.0-...-4c8c1f2 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2013 License: BSD-2-Clause Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidId       error = errors.New("auth: invalid id")
	ErrInvalidEmail    error = errors.New("auth: invalid email address")
	ErrDuplicateEmail  error = errors.New("auth: duplicate email address")
	ErrInvalidPassword error = errors.New("auth: invalid password")
)

Functions

This section is empty.

Types

type Address

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

type AuthMongoDBCtx

type AuthMongoDBCtx struct {
	// contains filtered or unexported fields
}

func NewAuthDBCtx

func NewAuthDBCtx(w http.ResponseWriter, r *http.Request, sess sessions.Provider,
	userColl, rememberColl *mgo.Collection) *AuthMongoDBCtx

func (*AuthMongoDBCtx) AddUser

func (a *AuthMongoDBCtx) AddUser(email, password string, notif, app bool) error

func (*AuthMongoDBCtx) AddUserInfo

func (a *AuthMongoDBCtx) AddUserInfo(email, password string, info Info,
	pri map[string]bool, notif, app bool) error

func (*AuthMongoDBCtx) CountUserOnline

func (a *AuthMongoDBCtx) CountUserOnline() int

func (*AuthMongoDBCtx) DeleteUser

func (a *AuthMongoDBCtx) DeleteUser(id string) error

func (*AuthMongoDBCtx) FindAllUser

func (a *AuthMongoDBCtx) FindAllUser(offsetKey string, limit int) ([]*User, error)

func (*AuthMongoDBCtx) FindUser

func (a *AuthMongoDBCtx) FindUser(id string) (*User, error)

func (*AuthMongoDBCtx) FindUserByEmail

func (a *AuthMongoDBCtx) FindUserByEmail(email string) (*User, error)

func (*AuthMongoDBCtx) FindUserOnline

func (a *AuthMongoDBCtx) FindUserOnline(offsetKey string, limit int) ([]*User, error)

func (*AuthMongoDBCtx) GetUser

func (a *AuthMongoDBCtx) GetUser() (*User, error)

func (*AuthMongoDBCtx) LogginUser

func (a *AuthMongoDBCtx) LogginUser(id string, remember int) error

func (*AuthMongoDBCtx) SetDomain

func (a *AuthMongoDBCtx) SetDomain(d string)

func (*AuthMongoDBCtx) SetFormatChecker

func (a *AuthMongoDBCtx) SetFormatChecker(c FormatChecker)

func (*AuthMongoDBCtx) SetHashFunc

func (a *AuthMongoDBCtx) SetHashFunc(h hash.Hash)

func (*AuthMongoDBCtx) SetNotificater

func (a *AuthMongoDBCtx) SetNotificater(n Notificater)

func (*AuthMongoDBCtx) SetOnlineThreshold

func (a *AuthMongoDBCtx) SetOnlineThreshold(t int)

func (*AuthMongoDBCtx) SetPath

func (a *AuthMongoDBCtx) SetPath(p string)

func (*AuthMongoDBCtx) ValidateUser

func (a *AuthMongoDBCtx) ValidateUser(email string, password string) (*User, error)

type Authenticater

type Authenticater interface {
	SetPath(p string)
	SetDomain(d string)
	// SetOnlineThreshold sets the online threshold time, if t <= 0, the loggin
	// state will last until the session expired.
	SetOnlineThreshold(t int)
	// 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) 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.
	AddUserInfo(email, pwd string, info Info, pri map[string]bool, notif, app 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 string) error
	// GetUser gets the infomations and update the LastActivity of the current
	// logged 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 string) (*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 string, limit int) ([]*User, error)
	// FindAllUserOline finds and return a slice of current logged user.
	// See FindAllUser for the usage.
	FindUserOnline(offsetId string, limit int) ([]*User, error)
	// CountUserOnline counts the number of user current logged.
	// 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)
	// LogginUser logs user in by using a session that store user id string.
	// Remember take a number of second to keep the user loggin state.
	// Developer must call LogginUser before send any output to browser.
	LogginUser(id string, remember int) error
}

type Config

type Config struct {
	Key   string `bson:"_id"`
	Value interface{}
}

type FormatChecker

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

type Info

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

type Notificater

type Notificater interface {
	AccountAdded(email string, app bool) error
	PasswordChanged(email string) error
}

type Password

type Password struct {
	Hashed []byte
	Salt   []byte
	InitAt 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 SimpleNotificater

type SimpleNotificater struct{}

func NewSimpleNotificater

func NewSimpleNotificater() *SimpleNotificater

func (*SimpleNotificater) AccountAdded

func (n *SimpleNotificater) AccountAdded(email string, app bool) error

func (*SimpleNotificater) PasswordChanged

func (n *SimpleNotificater) PasswordChanged(email string) error

type User

type User struct {
	Id        bson.ObjectId `bson:"_id,omitempty"`
	Email     string
	OldPwd    Password
	Pwd       Password
	Info      `bson:",inline"`
	Privilege map[string]bool
	Approved  bool
	ApprCode  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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