userbase

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2023 License: Apache-2.0 Imports: 11 Imported by: 1

Documentation

Index

Constants

View Source
const (
	UserSignupSignal signaling.Signal = "user-signup"
	UserLoginSignal  signaling.Signal = "user-login"
	UserLoadedSignal signaling.Signal = "user-loaded"
)
View Source
const CurrentAuthUserKey beContext.RequestKey = "current-auth-user"
View Source
const CurrentUserKey beContext.RequestKey = "current-user"

Variables

This section is empty.

Functions

func SetCurrentAuthUser added in v0.2.0

func SetCurrentAuthUser(u *AuthUser, r *http.Request) (modified *http.Request)

func SetCurrentUser

func SetCurrentUser(u *User, r *http.Request) (modified *http.Request)

Types

type Action added in v0.2.0

type Action string

Action is a kebab-cased name consisting of a verb, a subject (feature.Tag) and one or more additional details, separated by periods. For example: the action `view_fs-content_page` has a verb of "view", a subject of "fs-content" and one additional detail of "page". Details are individually converted to kebab-case and joined with hyphens, ie: `view_fs-content_page.search`

func NewAction added in v0.2.0

func NewAction(subject string, verb string, details ...string) Action

func ParseAction added in v0.2.0

func ParseAction(line string) (action Action)

func (Action) Details added in v0.2.0

func (a Action) Details() (details []string)

func (Action) String added in v0.2.0

func (a Action) String() string

func (Action) Subject added in v0.2.0

func (a Action) Subject() string

func (Action) Verb added in v0.2.0

func (a Action) Verb() string

type Actions added in v0.2.0

type Actions []Action

Actions are the collection of one or more groups

func NewActionsFromStringNL added in v0.2.0

func NewActionsFromStringNL(newlines string) (actions Actions)

func NewActionsFromStrings added in v0.2.0

func NewActionsFromStrings(slice ...string) (actions Actions)

func ParseActions added in v0.2.0

func ParseActions(lines string) (actions Actions, err error)

func (Actions) Append added in v0.2.0

func (a Actions) Append(actions ...Action) (modified Actions)

func (Actions) AsNewlines added in v0.2.0

func (a Actions) AsNewlines() (newlines string)

func (Actions) FilterKnown added in v0.2.0

func (a Actions) FilterKnown(other Actions) (known Actions)

func (Actions) FilterUnknown added in v0.2.0

func (a Actions) FilterUnknown(other Actions) (unknown Actions)

func (Actions) Has added in v0.2.0

func (a Actions) Has(action Action) (present bool)

func (Actions) HasSubject added in v0.2.0

func (a Actions) HasSubject(subject string) (present bool)

func (Actions) HasVerb added in v0.2.0

func (a Actions) HasVerb(verb string) (present bool)

func (Actions) Len added in v0.2.0

func (a Actions) Len() int

func (Actions) String added in v0.2.0

func (a Actions) String() (s string)

type AuthProvider

type AuthProvider interface {
	AuthenticateRequest(w http.ResponseWriter, r *http.Request) (handled bool, modified *http.Request)
}

type AuthUser added in v0.2.0

type AuthUser struct {
	RID     string            `json:"real-id"`
	EID     string            `json:"enjin-id"`
	Name    string            `json:"name"`
	Email   string            `json:"email"`
	Image   string            `json:"image"`
	Origin  string            `json:"origin"`
	Context beContext.Context `json:"context"`
}

func GetCurrentAuthUser added in v0.2.0

func GetCurrentAuthUser(r *http.Request) (u *AuthUser)

func NewAuthUser added in v0.2.0

func NewAuthUser(id, name, email, image string, ctx beContext.Context) (user *AuthUser)

type AuthUserApi added in v0.2.0

type AuthUserApi interface {
	RequireApiUser(next http.Handler) http.Handler
	RequireUserCan(action Action) func(next http.Handler) http.Handler
}

type AuthUserManager added in v0.2.0

type AuthUserManager interface {
	// NewAuthUser constructs a new AuthUser instance and saves it to the
	// userbase
	NewAuthUser(rid, name, email, picture, audience string, attributes map[string]interface{}) (user *AuthUser, err error)

	// SetAuthUser writes the given User to the system
	SetAuthUser(user *AuthUser) (err error)

	// RemoveAuthUser deletes a user from the system
	RemoveAuthUser(eid string) (err error)
}

type AuthUserProvider added in v0.2.0

type AuthUserProvider interface {
	// AuthUserPresent returns true if a user with the EID given is present
	AuthUserPresent(eid string) (present bool)

	// GetAuthUser returns the user by user.EID
	GetAuthUser(eid string) (user *AuthUser, err error)
}

type Group added in v0.2.0

type Group string

Group is the kebab-cased name of a user Group

func NewGroup added in v0.2.0

func NewGroup(group string) Group

func (Group) String added in v0.2.0

func (g Group) String() string

type Groups added in v0.2.0

type Groups []Group

Groups are the collection of one or more groups

func NewGroupsFromStringNL added in v0.2.0

func NewGroupsFromStringNL(newlines string) (groups Groups)

func NewGroupsFromStrings added in v0.2.0

func NewGroupsFromStrings(slice ...string) (groups Groups)

func (Groups) Append added in v0.2.0

func (g Groups) Append(groups ...Group) (modified Groups)

func (Groups) AppendString added in v0.2.0

func (g Groups) AppendString(names ...string) (modified Groups)

func (Groups) AsNewlines added in v0.2.0

func (g Groups) AsNewlines() (newlines string)

func (Groups) Has added in v0.2.0

func (g Groups) Has(group Group) (present bool)

func (Groups) Len added in v0.2.0

func (g Groups) Len() int

func (Groups) Remove added in v0.2.0

func (g Groups) Remove(groups ...Group) (modified Groups)

func (Groups) String added in v0.2.0

func (g Groups) String() (s string)

type GroupsManager added in v0.2.0

type GroupsManager interface {
	// GetGroupActions returns the list of actions associated with group
	GetGroupActions(group Group) (actions Actions)

	// UpdateGroup appends the given actions to the group, creating the group
	// if non exists
	UpdateGroup(group Group, actions ...Action) (err error)

	// RemoveGroup deletes the given group from the system. Does not delete any
	// fallback groups
	RemoveGroup(group Group) (err error)

	// AddUserToGroup adds a user to the list of groups given
	AddUserToGroup(eid string, groups ...Group) (err error)

	// RemoveUserFromGroup removes a user from each of the given groups
	RemoveUserFromGroup(eid string, groups ...Group) (err error)
}

type GroupsProvider

type GroupsProvider interface {
	// IsUserInGroup returns true if the user is in the given group
	IsUserInGroup(eid string, group Group) (present bool)

	// GetUserGroups returns the user's list of groups
	GetUserGroups(eid string) (groups Groups)
}

type SecretsProvider

type SecretsProvider interface {
	// GetUserSecret returns the user's password hash, returns "" if the user
	// secret is not found
	GetUserSecret(id string) (hash string)
}

type User

type User struct {
	page.Page
	AuthUser

	Origin string `json:"origin"`

	Groups  Groups  `json:"-"`
	Actions Actions `json:"-"`
}

func GetCurrentUser

func GetCurrentUser(r *http.Request) (u *User)

func NewUserFromPageMatter added in v0.2.0

func NewUserFromPageMatter(user *AuthUser, pm *matter.PageMatter, formats types.FormatProvider, enjin beContext.Context) (u *User, err error)

func (*User) AsPage added in v0.2.0

func (u *User) AsPage() *page.Page

func (*User) Can added in v0.2.0

func (u *User) Can(action Action) (allowed bool)

func (*User) FilteredContext added in v0.2.2

func (u *User) FilteredContext(includeKeys ...string) (ctx beContext.Context)

type UserActionsProvider added in v0.2.0

type UserActionsProvider interface {
	UserActions() (list Actions)
}

type UserManager added in v0.2.0

type UserManager interface {
	// NewUser constructs a new User instance and adds it to the userbase
	NewUser(au *AuthUser) (user *User, err error)

	// SetUser writes the given User to the system
	SetUser(user *User) (err error)

	// RemoveUser deletes a user from the system
	RemoveUser(eid string) (err error)
}

type UserProvider added in v0.2.0

type UserProvider interface {
	// GetUser returns the user by enjin ID
	GetUser(eid string) (user *User, err error)

	// ListUsers returns a paginated list of user EIDs
	ListUsers(start, page, numPerPage int) (list []string)
}

type UsersManager added in v0.2.0

type UsersManager interface {
	UserProvider
	UserManager
}

Jump to

Keyboard shortcuts

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