core

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2021 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BuiltInGroupAdmin     = "ADMIN"
	BuiltInGroupSpouse    = "SPOUSE"
	BuiltInGroupResident  = "RESIDENT"
	BuiltInGroupFriend    = "FRIEND"
	BuiltInGroupPowerUser = "POWER_USER"
	BuiltInGroupUser      = "USER"
)
View Source
const (
	PermissionResetUserPassword   = "RESET_USER_PASSWORD"
	PermissionSetAdmin            = "SET_ADMIN"
	PermissionProxyAsUser         = "PROXY_AS_USER"
	PermissionViewAppSettings     = "VIEW_APP_SETTINGS"
	PermissionChangeAppSettings   = "CHANGE_APP_SETTINGS"
	PermissionManageAppDeployment = "MANAGE_APP_DEPLOYMENT"
	PermissionStopServer          = "STOP_SERVER"
	PermissionManageIndexes       = "MANAGE_INDEXES"
	PermissionLogging             = "LOGGING"
)

Elevated permissions

View Source
const (
	PermissionPostComments     = "POST_COMMENTS"
	PermissionEditUserInfo     = "EDIT_USER_INFO"
	PermissionUnlockUser       = "UNLOCK_USER"
	PermissionViewUsers        = "VIEW_USERS"
	PermissionEditGroups       = "EDIT_GROUPS"
	PermissionViewGroups       = "VIEW_GROUPS"
	PermissionManageIOTDevices = "MANAGE_IOT_DEVICES"
)
View Source
const (
	PermissionListProjects    = "LIST_PROJECTS"
	PermissionViewEchoHistory = "VIEW_ECHO_HISTORY"
)

Projects Module

View Source
const GroupPrefix = "GROUP:"
View Source
const (
	PermissionSetDefaultParty = "SET_DEFAULT_PARTY"
)

Visit module

View Source
const SessionPrefix = "SESSION:"
View Source
const UserGroupPrefix = "USERGROUP:"
View Source
const UserPrefix = "USER:"

Variables

Functions

func IP

func IP(r *http.Request) string

Types

type Current

type Current struct {
	User    UserInfo `json:"user"`
	Session Session  `json:"session"`
	// contains filtered or unexported fields
}

Current holds details about the current user. The zero value is an anonymous user.

func GetCurrent

func GetCurrent(token string, db Providers) (Current, error)

GetCurrent returns details about the current user based upon the token provided. If the token is empty or there is an error getting this information, the current values will be for the anonymous user.

func (Current) Anonymous added in v0.3.0

func (c Current) Anonymous() bool

Anonymous returns whether the current user ID is 0, the anonymous user

func (Current) Authenticated

func (c Current) Authenticated() bool

Authenticated returns whether the current user is not anonymous by checking that the user id is non-zero

func (Current) Can

func (c Current) Can(permission string) errs.Error

Can asks if a user can do something. It returns nil if a user is in a group with the specified permission. Admins always return nil because they can do anything. Otherwise can returns an appropriate StatusError.

if err := cur.Can(core.PermissionViewAppSettings); err != nil {
	return err
}

func (Current) Is

func (c Current) Is(groupName string) (bool, error)

Is checks that that current user has a user group membership in the group named

func (*Current) LogString

func (c *Current) LogString() string

func (Current) String

func (c Current) String() string

type DisplayName

type DisplayName string

func (DisplayName) Tag

func (d DisplayName) Tag() string

type Email added in v0.3.0

type Email struct {
	Email                string    `json:"email"`
	Verified             bool      `json:"verified"`
	VerifiedDate         time.Time `json:"verifiedDate"`
	VerificationCode     string    `json:"-"`
	VerificationCodeDate time.Time `json:"-"`
}

type Group

type Group struct {
	Name             string         `json:"name"`
	Permissions      []string       `json:"permissions"`
	Requires2FA      bool           `json:"requires2FA"`
	RequiresVaultPIN bool           `json:"requiresVaultPIN"`
	ModifiedBy       store.Identity `json:"modifiedBy"`
	ModifiedDate     time.Time      `json:"modifiedDate"`
}

func (Group) HasPermission

func (g Group) HasPermission(permission string) bool

func (Group) Key

func (g Group) Key() []byte

func (Group) Prefix

func (g Group) Prefix() []byte

type GroupCreationRequest

type GroupCreationRequest struct {
	Name             string `json:"name"`
	Requires2FA      bool   `json:"requires2FA"`
	RequiresVaultPIN bool   `json:"requiresVaultPIN"`
}

func (GroupCreationRequest) Group

func (req GroupCreationRequest) Group(modifiedBy store.Identity) Group

type GroupProvider

type GroupProvider interface {
	GroupsFor(userID store.Identity) ([]Group, error)
	Get(name string) (Group, error)
	Exists(name string) (bool, error)
	Set(group Group) error
	All() ([]Group, error)
	Delete(name string) error
}

type Hash

type Hash []byte

func CreateHash

func CreateHash(password string) (Hash, error)

func (Hash) Check

func (hash Hash) Check(password string) bool

type LoginRequest

type LoginRequest struct {
	Email    string `json:"email"`
	Password string `json:"password"`
}

type LoginResponse added in v0.3.0

type LoginResponse struct {
	LoginResult       LoginResult `json:"loginResult"`
	IntermediateToken *string     `json:"intermediateToken,omitempty"`
	Me                *Me         `json:"me,omitempty"`
}

type LoginResult

type LoginResult int
const (
	LoginResultSuccess          LoginResult = iota // 0
	LoginResultBadCredentials                      // 1
	LoginResultEmailNotVerified                    // 2
	LoginResult2FA                                 // 3
	LoginResultChangePassword                      // 4
	LoginResultLockedOrDisabled                    // 5
	LoginResultError                               // 6
)

type Me

type Me struct {
	User    UserInfo `json:"user"`
	Session Session  `json:"session"`
	Groups  []Group  `json:"groups"`
}

type Providers

type Providers struct {
	Sessions   SessionProvider
	Users      UserProvider
	Groups     GroupProvider
	UserGroups UserGroupProvider
}

type Session

type Session struct {
	Token         string         `json:"token"`
	UserID        store.Identity `json:"userID"`
	IP            string         `json:"ip"`
	Proxy         bool           `json:"proxy"`
	VaultUnlocked bool           `json:"vaultUnlocked"`
	CreatedDate   time.Time      `json:"createdDate"`
	Heartbeat     time.Time      `json:"heartbeat"`
}

func (Session) Info added in v0.3.0

func (s Session) Info() SessionInfo

func (Session) Key

func (s Session) Key() []byte

func (Session) Prefix

func (s Session) Prefix() []byte

type SessionInfo added in v0.3.0

type SessionInfo struct {
	IP          string    `json:"ip"`
	Proxy       bool      `json:"proxy"`
	CreatedDate time.Time `json:"createdDate"`
	Heartbeat   time.Time `json:"heartbeat"`
}

type SessionProvider

type SessionProvider interface {
	Get(token string) (Session, error)
	Exists(token string) (bool, error)
	Set(session Session) error
	GenerateFor(userID store.Identity, ip string) Session
	All() ([]Session, error)
	Delete(token string) error
	PurgeAll() error
	UpdateHeartbeat(session *Session, ip string) error
	DoLogin(req LoginRequest, ip string) (UserInfo, Session, LoginResult, error)
}

type User

type User struct {
	ID                    store.Identity `json:"id"`
	GoogleID              string         `json:"googleId"`
	GoogleImportDate      time.Time      `json:"googleImportDate"`
	PrimaryEmail          string         `json:"primaryEmail"`
	Emails                []Email        `json:"emails"`
	Tag                   string         `json:"tag"`
	PreviousTags          []string       `json:"previousTags"`
	PasswordHash          Hash           `json:"-"`
	LastPasswordHash      Hash           `json:"-"`
	MustChangePWNextLogin bool           `json:"mustChangePWNextLogin"`
	Require2FA            bool           `json:"require2FA"`
	VaultPIN              string         `json:"-"`
	Locked                bool           `json:"locked"`
	Disabled              bool           `json:"disabled"`
	LoginAttempts         int            `json:"loginAttempts"`
	LastFailedLogin       time.Time      `json:"lastFailedLogin"`
	DisplayName           DisplayName    `json:"displayName"`
	GivenName             string         `json:"givenName"`
	FamilyName            string         `json:"familyName"`
	Link                  string         `json:"link"`
	Picture               string         `json:"picture"`
	Gender                string         `json:"gender"`
	Locale                string         `json:"locale"`
	LastLogin             time.Time      `json:"lastLogin"`
	ModifiedDate          time.Time      `json:"modifiedDate"`
	CreatedDate           time.Time      `json:"createdDate"`
}

func (User) CanLogin

func (u User) CanLogin() bool

func (User) Info

func (u User) Info() UserInfo

func (User) Key

func (u User) Key() []byte

func (User) Prefix

func (u User) Prefix() []byte

type UserGroup

type UserGroup struct {
	UserID      store.Identity `json:"userID"`
	GroupName   string         `json:"groupName"`
	CreatedDate time.Time      `json:"createdDate"`
}

func (UserGroup) Key

func (u UserGroup) Key() []byte

func (UserGroup) Prefix

func (u UserGroup) Prefix() []byte

type UserGroupProvider

type UserGroupProvider interface {
	Get(userID store.Identity, groupName string) (UserGroup, error)
	Exists(userID store.Identity, groupName string) (bool, error)
	Set(userGroup UserGroup) error
	All() ([]UserGroup, error)
	Delete(userID store.Identity, groupName string) error
}

type UserInfo

type UserInfo struct {
	User
	HasPassword bool `json:"hasPassword"`
	HasVaultPIN bool `json:"hasVaultPIN"`
}

type UserProvider

type UserProvider interface {
	UserSearcher

	UsersFor(groupName string) ([]User, error)
	Get(userID store.Identity) (User, error)
	Exists(userID store.Identity) (bool, error)
	Set(user User) error
	Count() (int, error)
	All() ([]User, error)
	Delete(userID store.Identity) error
	PurgeAll() error
}

type UserSearcher

type UserSearcher interface {
	Index(u User) error
	Deindex(u User) error
	Reindex() error
	CompletionSuggestions(query string) ([]User, error)
	FromEmail(email string) (User, error)
	WithEmail(email string) ([]User, error)
	EmailExists(email string) (bool, error)
	VerifiedEmailExists(email string) (bool, error)
}

type Users

type Users []User

func (Users) Info

func (users Users) Info() []UserInfo

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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