user

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ScopeCanSendChatMessages will allow sending chat messages as itself.
	ScopeCanSendChatMessages = "CAN_SEND_MESSAGES"
	// ScopeCanSendSystemMessages will allow sending chat messages as the system.
	ScopeCanSendSystemMessages = "CAN_SEND_SYSTEM_MESSAGES"
	// ScopeHasAdminAccess will allow performing administrative actions on the server.
	ScopeHasAdminAccess = "HAS_ADMIN_ACCESS"
)

Variables

This section is empty.

Functions

func ChangeUsername

func ChangeUsername(userID string, username string)

ChangeUsername will change the user associated to userID from one display name to another.

func DeleteExternalAPIUser

func DeleteExternalAPIUser(token string) error

DeleteExternalAPIUser will delete a token from the database.

func GetIntegrationNameForAccessToken

func GetIntegrationNameForAccessToken(token string) *string

GetIntegrationNameForAccessToken will return the integration name associated with a specific access token.

func HasValidScopes

func HasValidScopes(scopes []string) bool

HasValidScopes will verify that all the scopes provided are valid.

func InsertExternalAPIUser

func InsertExternalAPIUser(token string, name string, color int, scopes []string) error

InsertExternalAPIUser will add a new API user to the database.

func SetEnabled

func SetEnabled(userID string, enabled bool) error

SetEnabled will will set the enabled flag on a single user assigned to userID.

func SetExternalAPIUserAccessTokenAsUsed

func SetExternalAPIUserAccessTokenAsUsed(token string) error

SetExternalAPIUserAccessTokenAsUsed will update the last used timestamp for a token.

func SetupUsers

func SetupUsers()

SetupUsers will perform the initial initialization of the user package.

Types

type ExternalAPIUser

type ExternalAPIUser struct {
	ID           string     `json:"id"`
	AccessToken  string     `json:"accessToken"`
	DisplayName  string     `json:"displayName"`
	DisplayColor int        `json:"displayColor"`
	CreatedAt    time.Time  `json:"createdAt"`
	Scopes       []string   `json:"scopes"`
	Type         string     `json:"type,omitempty"` // Should be API
	LastUsedAt   *time.Time `json:"lastUsedAt,omitempty"`
}

ExternalAPIUser represents a single 3rd party integration that uses an access token. This struct mostly matches the User struct so they can be used interchangeably.

func GetExternalAPIUser

func GetExternalAPIUser() ([]ExternalAPIUser, error)

GetExternalAPIUser will return all access tokens.

func GetExternalAPIUserForAccessTokenAndScope

func GetExternalAPIUserForAccessTokenAndScope(token string, scope string) (*ExternalAPIUser, error)

GetExternalAPIUserForAccessTokenAndScope will determine if a specific token has access to perform a scoped action.

type User

type User struct {
	ID            string     `json:"id"`
	AccessToken   string     `json:"-"`
	DisplayName   string     `json:"displayName"`
	DisplayColor  int        `json:"displayColor"`
	CreatedAt     time.Time  `json:"createdAt"`
	DisabledAt    *time.Time `json:"disabledAt,omitempty"`
	PreviousNames []string   `json:"previousNames"`
	NameChangedAt *time.Time `json:"nameChangedAt,omitempty"`
}

User represents a single chat user.

func CreateAnonymousUser

func CreateAnonymousUser(username string) (*User, error)

CreateAnonymousUser will create a new anonymous user with the provided display name.

func GetDisabledUsers

func GetDisabledUsers() []*User

GetDisabledUsers will return back all the currently disabled users that are not API users.

func GetUserByID

func GetUserByID(id string) *User

GetUserByID will return a user by a user ID.

func GetUserByToken

func GetUserByToken(token string) *User

GetUserByToken will return a user by an access token.

func (*User) IsEnabled

func (u *User) IsEnabled() bool

IsEnabled will return if this single user is enabled.

Jump to

Keyboard shortcuts

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