Documentation ¶
Index ¶
- Constants
- Variables
- func AddUser(u *User) error
- func ChangeUsername(u *User, newUsername string) error
- func DeleteUser(u *User) error
- func Groups() []string
- func IsAuth(s *bitmonster.Socket) bool
- func MustAdminGroup() bitmonster.Hook
- func MustGroup(groups ...string) bitmonster.Hook
- func MustIsAuth() bitmonster.Hook
- func OffDeleteUser(f OnDeleteUserFunc)
- func OffNewUser(f OnNewUserFunc)
- func OnDeleteUser(f OnDeleteUserFunc)
- func OnNewUser(f OnNewUserFunc)
- func RegisterGroup(name string) error
- func UpdateUser(u *User) error
- type AuthSession
- type AuthSessions
- type OnDeleteUserFunc
- type OnNewUserFunc
- type User
- func (u *User) AddGroup(groups ...string)
- func (u *User) ChangePassword(password string) (err error)
- func (u *User) ClearAuthSessions()
- func (u *User) ComparePasswords(password string) (match bool)
- func (u *User) HasGroup(group string) bool
- func (u *User) RemoveGroup(groups ...string)
- func (u *User) Validate() error
- type Users
Constants ¶
const ( DBTableUsers = "auth_users" DBTableUsersUsernameIndex = "username" )
const (
// AdminGroup is the administration group.
AdminGroup = "admin"
)
const (
// ModuleName specifies the BitMonster module name.
ModuleName = "auth"
)
Variables ¶
var ( ErrEmptyResult = errors.New("empty result") ErrUserNotFound = errors.New("user not found") ErrUsernameAlreadyExists = errors.New("a user with the username already exists") )
var (
ErrNotAuth = errors.New("not authenticated")
)
Functions ¶
func AddUser ¶
AddUser adds a new user to the database. Returns ErrUsernameAlreadyExists if the username already exists.
func ChangeUsername ¶
ChangeUsername changes the username of the user in the database. Returns ErrUsernameAlreadyExists if the username already exists. Hint: This implementation is currently not atomic if multiple BitMonster instances are used to provide the backend service. This is due to limitations of the RethinkDB database. See TODO. See: https://github.com/rethinkdb/rethinkdb/issues/1716
func IsAuth ¶
func IsAuth(s *bitmonster.Socket) bool
IsAuth returns a boolean whenever the socket is authentication by a user.
func MustAdminGroup ¶
func MustAdminGroup() bitmonster.Hook
MustAdminGroup returns a BitMonster Hook which requires an authenticated user who is member of the admin group.
func MustGroup ¶
func MustGroup(groups ...string) bitmonster.Hook
MustGroup returns a BitMonster Hook which requires an authenticated user who is member of one of the passed groups.
func MustIsAuth ¶
func MustIsAuth() bitmonster.Hook
MustIsAuth returns a BitMonster Hook which requires an authenticated user session.
func OffDeleteUser ¶
func OffDeleteUser(f OnDeleteUserFunc)
OffDeleteUser unbinds the event function again.
func OnDeleteUser ¶
func OnDeleteUser(f OnDeleteUserFunc)
OnDeleteUser triggers the event function if an user was deleted by the current BitMonster server instance. To listen for all database change events of all running instances, use the changefeeds package.
func OnNewUser ¶
func OnNewUser(f OnNewUserFunc)
OnNewUser triggers the event function if an user was added by the current BitMonster server instance. To listen for all database change events of all running instances, use the changefeeds package.
func RegisterGroup ¶
RegisterGroup registers a new group. This method should only be called during the initialization process.
func UpdateUser ¶
UpdateUser updates a user in the database. The user fields replace all fields of the document stored in the database. Don't call this function if the username of the user was changed. Instead use ChangeUsername to change usernames.
Types ¶
type AuthSession ¶
type AuthSessions ¶
type AuthSessions map[string]*AuthSession
type OnDeleteUserFunc ¶
type OnDeleteUserFunc func(user *User)
type OnNewUserFunc ¶
type OnNewUserFunc func(user *User)
type User ¶
type User struct { ID string `gorethink:"id" json:"id" valid:"uuidv4,required"` Username string `gorethink:"username" json:"username" valid:"printableascii,length(3|50),required"` Name string `gorethink:"name" json:"name"` Email string `gorethink:"email" json:"email" valid:"email,length(3|100),required"` Enabled bool `gorethink:"enabled" json:"enabled"` Groups []string `gorethink:"groups" json:"groups"` Created time.Time `gorethink:"created" json:"created"` LastLogin time.Time `gorethink:"lastLogin" json:"lastLogin"` AuthSessions AuthSessions `gorethink:"authSessions" json:"-"` PasswordHash string `gorethink:"passwordHash" json:"-"` }
func CurrentUser ¶
func CurrentUser(s *bitmonster.Socket, enableCache ...bool) (*User, error)
CurrentUser returns the current authenticated user of the socket session. If the socket session is not authenticated, then ErrNotAuth is returned. Optionally pass one variadic boolean to enable caching. If caching is enabled, multiple calls to this method will return the cached user value instead of always obtaining the value from the database. Note: The cached value might be out-of-date. Don't enable the cache if the returned user value is used to be written to the database.
func GetUser ¶
GetUser obtains a user by its ID. Returns a ErrUserNotFound error if the user does not exists.
func GetUserByUsername ¶
GetUserByUsername obtains a user by its username. Returns a ErrUserNotFound error if the user does not exists.
func (*User) ChangePassword ¶
ChangePassword changes a user's password.
func (*User) ClearAuthSessions ¶
func (u *User) ClearAuthSessions()
ClearAuthSessions removes all current authenticated sessions of the user. This will force an overall relogin.
func (*User) ComparePasswords ¶
ComparePasswords compares the passed password with the user's password hash. This method is safe against timing attacks.
func (*User) RemoveGroup ¶
RemoveGroup removes the user from the group(s).
type Users ¶
type Users []*User
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package changefeeds provides the database change events for the auth package.
|
Package changefeeds provides the database change events for the auth package. |