auth

package
v0.0.0-...-55d16bb Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2017 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Page Urls
	LoginPageUrl    = "/login"
	RegisterPageUrl = "/register"
)
View Source
const (
	DBUserTable      = "users"
	DBUserTableIndex = "LoginName"
)
View Source
const (

	// System operator (system administrator): full access to the system.
	GroupSysOp = "sysop"

	// Administrator: client of the application. Administration of the page content and some basic stuff...
	GroupAdmin = "admin"
)

Variables

This section is empty.

Functions

func Init

func Init() (err error)

func IsAuth

func IsAuth(i interface{}) bool

IsAuth returns a boolean if the current session is authenticated by a user login. You can pass a session or context value to this method. If a context value is available, then always pass it instead of the session. This will improve the performance and won't retrieve a user value multiple times from the database during one template execution cycle.

func Logout

func Logout(s *sessions.Session)

Logout logs out the user if authenticated.

func NavigateToLoginPage(s *sessions.Session)
func NavigateToRegisterPage(s *sessions.Session)

func OffEndAuthenticatedSession

func OffEndAuthenticatedSession(f func(s *sessions.Session))

OffEndAuthenticatedSession removes the listener again

func OffNewAuthenticatedSession

func OffNewAuthenticatedSession(f func(s *sessions.Session))

OffNewAuthenticatedSession removes the listener again

func OffRemovedUser

func OffRemovedUser(f func(userID string))

OffRemovedUser removes the listener again

func OnEndAuthenticatedSession

func OnEndAuthenticatedSession(f func(s *sessions.Session))

OnEndAuthenticatedSession sets the function which is triggered during each logout

func OnNewAuthenticatedSession

func OnNewAuthenticatedSession(f func(s *sessions.Session))

OnNewAuthenticatedSession sets the function which is triggered during each new authenticated session

func OnRemovedUser

func OnRemovedUser(f func(userID string))

OnRemovedUser sets the function which is triggered if a user is removed.

func RegisterGroup

func RegisterGroup(name string, description string) error

RegisterGroup registeres a group. It is suggested to only use lower characters.

func Release

func Release()

Release this package.

func RemoveUser

func RemoveUser(id string) error

func ShowChangePasswordDialog

func ShowChangePasswordDialog(s *sessions.Session, u *User, opts ...ChangePasswordDialogOpts) error

ShowChangePasswordDialog shows a change password dialog for the given user. One optional parameter can be passed, defining a callback name for the callback package. This callback is executed on success.

Types

type ChangePasswordDialogOpts

type ChangePasswordDialogOpts struct {
	// If true, a success message box is shown to the user.
	ShowSuccessMsgBox bool

	// If not empty, the callback specified by the name for
	// the callback package is executed on success.
	CallbackName string
}

type Group

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

func (*Group) Description

func (g *Group) Description() string

func (*Group) Name

func (g *Group) Name() string

type Groups

type Groups []*Group

func GetGroups

func GetGroups() Groups

GetGroups returns a slice of all available groups

type User

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

func AddUser

func AddUser(loginName string, name string, email string, password string, removeOnExpire bool, groups ...string) (*User, error)

AddUser adds a new user to the database. If removeOnExpire is true, the user will be removed automatically if not logged in once for the expire timeout.

func GetUser

func GetUser(i interface{}) *User

GetUser returns the logged in user value if logged in. Otherwise nil is returned. This user value is not updated, if any user data changes! Call user.Update() to get the latest state. You can pass a session or context value to this method. If a context value is available, then always pass it instead of the session. This will improve the performance and won't retrieve a user value multiple times from the database during one template execution cycle. This method returns nil, if the user is not enabled.

func GetUserByID

func GetUserByID(id string) (*User, error)

GetUserByID retreives the user with the ID from the database.

func GetUserByLoginName

func GetUserByLoginName(name string) (*User, error)

GetUserByLoginName retreives the user with the login name from the database.

func (*User) AddGroup

func (u *User) AddGroup(groups ...string)

AddGroup adds the user to the group. You have to call the commit method to make this persistent.

func (*User) Commit

func (u *User) Commit() error

Commit all changes to the database.

func (*User) Created

func (u *User) Created() int64

func (*User) EMail

func (u *User) EMail() string

func (*User) Enabled

func (u *User) Enabled() bool

func (*User) Groups

func (u *User) Groups() []string

func (*User) ID

func (u *User) ID() string

func (*User) IsAdmin

func (u *User) IsAdmin() bool

IsAdmin returns a boolean if the user is an administrator.

func (*User) IsInGroup

func (u *User) IsInGroup(groups ...string) bool

IsInGroup returns true if the user is in one of the passed groups. True is returned if no groups are passed.

func (*User) IsInGroups

func (u *User) IsInGroups(groups []string) bool

IsInGroups accepts a slice instead of variadic arguments. This might be useful if called from templates directly.

func (*User) IsSysOp

func (u *User) IsSysOp() bool

IsSysOp returns a boolean if the user is a system operator.

func (*User) LastLogin

func (u *User) LastLogin() int64

func (*User) LoginName

func (u *User) LoginName() string

func (*User) Name

func (u *User) Name() string

func (*User) SetEMail

func (u *User) SetEMail(email string)

SetEMail sets the user's e-mail. You have to call the commit method to make this persistent.

func (*User) SetEnabled

func (u *User) SetEnabled(enabled bool)

SetEnabled activates or disables the user. You have to call the commit method to make this persistent.

func (*User) SetLoginName

func (u *User) SetLoginName(loginName string)

SetLoginName sets the user's login name. You have to call the commit method to make this persistent.

func (*User) SetName

func (u *User) SetName(name string)

SetName sets the user's name. You have to call the commit method to make this persistent.

func (*User) Update

func (u *User) Update() error

Update the user data, by retreiving the data from the database.

type Users

type Users []*User

func GetUsersInGroup

func GetUsersInGroup(group string) (Users, error)

GetUsersInGroup retreives all users from the database which are in the desired group.

Jump to

Keyboard shortcuts

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