Documentation ¶
Index ¶
- Constants
- Variables
- func CountOtherUsers(tx *storage.Connection, instanceID, id uuid.UUID) (int, error)
- func DeleteInstance(conn *storage.Connection, instance *Instance) error
- func FindUserWithRefreshToken(tx *storage.Connection, token string) (*User, *RefreshToken, error)
- func IsDuplicatedEmail(tx *storage.Connection, instanceID uuid.UUID, email, aud string) (bool, error)
- func IsNotFoundError(err error) bool
- func Logout(tx *storage.Connection, instanceID uuid.UUID, id uuid.UUID) error
- func NewAuditLogEntry(tx *storage.Connection, instanceID uuid.UUID, actor *User, action AuditAction, ...) error
- type AuditAction
- type AuditLogEntry
- type Instance
- type InstanceNotFoundError
- type JSONMap
- type Pagination
- type RefreshToken
- type RefreshTokenNotFoundError
- type SortDirection
- type SortField
- type SortParams
- type User
- func FindUserByConfirmationToken(tx *storage.Connection, token string) (*User, error)
- func FindUserByEmailAndAudience(tx *storage.Connection, instanceID uuid.UUID, email, aud string) (*User, error)
- func FindUserByID(tx *storage.Connection, id uuid.UUID) (*User, error)
- func FindUserByInstanceIDAndID(tx *storage.Connection, instanceID, id uuid.UUID) (*User, error)
- func FindUserByRecoveryToken(tx *storage.Connection, token string) (*User, error)
- func FindUsersInAudience(tx *storage.Connection, instanceID uuid.UUID, aud string, ...) ([]*User, error)
- func NewSystemUser(instanceID uuid.UUID, aud string) *User
- func NewUser(instanceID uuid.UUID, email, password, aud string, ...) (*User, error)
- func (u *User) Authenticate(password string) bool
- func (u *User) BeforeCreate(tx *gorm.DB) error
- func (u *User) BeforeSave(tx *gorm.DB) error
- func (u *User) BeforeUpdate(tx *gorm.DB) error
- func (u *User) Confirm(tx *storage.Connection) error
- func (u *User) ConfirmEmailChange(tx *storage.Connection) error
- func (u *User) HasRole(roleName string) bool
- func (u *User) IsConfirmed() bool
- func (u *User) Recover(tx *storage.Connection) error
- func (u *User) SetEmail(tx *storage.Connection, email string) error
- func (u *User) SetRole(tx *storage.Connection, roleName string) error
- func (u *User) UpdateAppMetaData(tx *storage.Connection, updates map[string]interface{}) error
- func (u *User) UpdatePassword(tx *storage.Connection, password string) error
- func (u *User) UpdateUserMetaData(tx *storage.Connection, updates map[string]interface{}) error
- type UserNotFoundError
Constants ¶
const CreatedAt = "created_at"
const SystemUserID = "0"
Variables ¶
var SystemUserUUID = uuid.Nil
Functions ¶
func CountOtherUsers ¶
CountOtherUsers counts how many other users exist besides the one provided
func DeleteInstance ¶
func DeleteInstance(conn *storage.Connection, instance *Instance) error
func FindUserWithRefreshToken ¶
func FindUserWithRefreshToken(tx *storage.Connection, token string) (*User, *RefreshToken, error)
FindUserWithRefreshToken finds a user from the provided refresh token.
func IsDuplicatedEmail ¶
func IsDuplicatedEmail(tx *storage.Connection, instanceID uuid.UUID, email, aud string) (bool, error)
IsDuplicatedEmail returns whether a user exists with a matching email and audience.
func IsNotFoundError ¶
IsNotFoundError returns whether an error represents a "not found" error.
func NewAuditLogEntry ¶
func NewAuditLogEntry(tx *storage.Connection, instanceID uuid.UUID, actor *User, action AuditAction, traits map[string]interface{}) error
Types ¶
type AuditAction ¶
type AuditAction string
const ( LoginAction AuditAction = "login" LogoutAction AuditAction = "logout" InviteAcceptedAction AuditAction = "invite_accepted" UserSignedUpAction AuditAction = "user_signedup" UserInvitedAction AuditAction = "user_invited" UserDeletedAction AuditAction = "user_deleted" UserModifiedAction AuditAction = "user_modified" UserRecoveryRequestedAction AuditAction = "user_recovery_requested" TokenRevokedAction AuditAction = "token_revoked" TokenRefreshedAction AuditAction = "token_refreshed" )
type AuditLogEntry ¶
type AuditLogEntry struct { InstanceID uuid.UUID `json:"-" gorm:"index:audit_logs_instance_id_idx;type:varchar(255) DEFAULT NULL"` ID uuid.UUID `json:"id" gorm:"primaryKey;type:varchar(255) NOT NULL"` Payload JSONMap `json:"payload" gorm:"type:JSON NULL DEFAULT NULL"` CreatedAt time.Time `json:"created_at" gorm:"type:timestamp NULL DEFAULT NULL"` }
AuditLogEntry is the database model for audit log entries.
func FindAuditLogEntries ¶
func FindAuditLogEntries(tx *storage.Connection, instanceID uuid.UUID, filterColumns []string, filterValue string, pageParams *Pagination) ([]*AuditLogEntry, error)
type Instance ¶
type Instance struct { ID uuid.UUID `json:"id" gorm:"primaryKey;type:varchar(255) NOT NULL"` // Gothic UUID UUID uuid.UUID `json:"uuid,omitempty" gorm:"type:varchar(255) DEFAULT NULL"` BaseConfig *conf.Configuration `json:"config" gorm:"column:raw_base_config"` CreatedAt time.Time `json:"created_at" gorm:"type:timestamp NULL DEFAULT NULL"` UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamp NULL DEFAULT NULL"` }
func GetInstance ¶
GetInstance finds an instance by ID
func GetInstanceByUUID ¶
func (*Instance) Config ¶
func (i *Instance) Config() (*conf.Configuration, error)
Config loads the the base configuration values with defaults.
func (*Instance) UpdateConfig ¶
func (i *Instance) UpdateConfig(tx *storage.Connection, config *conf.Configuration) error
UpdateConfig updates the base config
type InstanceNotFoundError ¶
type InstanceNotFoundError struct{}
InstanceNotFoundError represents when an instance is not found.
func (InstanceNotFoundError) Error ¶
func (e InstanceNotFoundError) Error() string
type Pagination ¶
func (*Pagination) Offset ¶
func (p *Pagination) Offset() uint64
type RefreshToken ¶
type RefreshToken struct { InstanceID uuid.UUID `` /* 128-byte string literal not displayed */ ID int64 `gorm:"primaryKey"` Token string `gorm:"index:refresh_tokens_token_idx;type:varchar(255) DEFAULT NULL"` UserID uuid.UUID `gorm:"index:refresh_tokens_instance_id_user_id_idx;type:varchar(255) DEFAULT NULL"` Revoked bool `gorm:"type:tinyint(1) DEFAULT NULL"` CreatedAt time.Time `gorm:"type:timestamp NULL DEFAULT NULL"` UpdatedAt time.Time `gorm:"type:timestamp NULL DEFAULT NULL"` }
RefreshToken is the database model for refresh tokens.
func GrantAuthenticatedUser ¶
func GrantAuthenticatedUser(tx *storage.Connection, user *User) (*RefreshToken, error)
GrantAuthenticatedUser creates a refresh token for the provided user.
func GrantRefreshTokenSwap ¶
func GrantRefreshTokenSwap(tx *storage.Connection, user *User, token *RefreshToken) (*RefreshToken, error)
GrantRefreshTokenSwap swaps a refresh token for a new one, revoking the provided token.
type RefreshTokenNotFoundError ¶
type RefreshTokenNotFoundError struct{}
RefreshTokenNotFoundError represents when a refresh token is not found.
func (RefreshTokenNotFoundError) Error ¶
func (e RefreshTokenNotFoundError) Error() string
type SortDirection ¶
type SortDirection string
const Ascending SortDirection = "ASC"
const Descending SortDirection = "DESC"
type SortField ¶
type SortField struct { Name string Dir SortDirection }
type SortParams ¶
type SortParams struct {
Fields []SortField
}
type User ¶
type User struct { InstanceID uuid.UUID `json:"-" gorm:"index:users_instance_id_idx;index:users_instance_id_email_idx;type:varchar(255) DEFAULT NULL"` ID uuid.UUID `json:"id" gorm:"primaryKey;type:varchar(255) NOT NULL"` Aud string `json:"aud" gorm:"type:varchar(255) DEFAULT NULL"` Role string `json:"role" gorm:"type:varchar(255) DEFAULT NULL"` Email string `json:"email" gorm:"index:users_instance_id_email_idx;type:varchar(255) DEFAULT NULL"` EncryptedPassword string `json:"-" gorm:"type:varchar(255) DEFAULT NULL"` ConfirmedAt *time.Time `json:"confirmed_at,omitempty" gorm:"type:timestamp NULL DEFAULT NULL"` InvitedAt *time.Time `json:"invited_at,omitempty" gorm:"type:timestamp NULL DEFAULT NULL"` ConfirmationToken string `json:"-" gorm:"type:varchar(255) DEFAULT NULL"` ConfirmationSentAt *time.Time `json:"confirmation_sent_at,omitempty" gorm:"type:timestamp NULL DEFAULT NULL"` RecoveryToken string `json:"-" gorm:"type:varchar(255) DEFAULT NULL"` RecoverySentAt *time.Time `json:"recovery_sent_at,omitempty" gorm:"type:timestamp NULL DEFAULT NULL"` EmailChangeToken string `json:"-" gorm:"type:varchar(255) DEFAULT NULL"` EmailChange string `json:"new_email,omitempty" gorm:"type:varchar(255) DEFAULT NULL"` EmailChangeSentAt *time.Time `json:"email_change_sent_at,omitempty" gorm:"type:timestamp NULL DEFAULT NULL"` LastSignInAt *time.Time `json:"last_sign_in_at,omitempty" gorm:"type:timestamp NULL DEFAULT NULL"` AppMetaData JSONMap `json:"app_metadata" gorm:"column:raw_app_meta_data;type:JSON NULL DEFAULT NULL"` UserMetaData JSONMap `json:"user_metadata" gorm:"column:raw_user_meta_data;type:JSON NULL DEFAULT NULL"` IsSuperAdmin bool `json:"-" gorm:"type:tinyint(1) DEFAULT NULL"` CreatedAt time.Time `json:"created_at" gorm:"type:timestamp NULL DEFAULT NULL"` UpdatedAt time.Time `json:"updated_at" gorm:"type:timestamp NULL DEFAULT NULL"` }
User represents a registered user with email/password authentication
func FindUserByConfirmationToken ¶
func FindUserByConfirmationToken(tx *storage.Connection, token string) (*User, error)
FindUserByConfirmationToken finds users with the matching confirmation token.
func FindUserByEmailAndAudience ¶
func FindUserByEmailAndAudience(tx *storage.Connection, instanceID uuid.UUID, email, aud string) (*User, error)
FindUserByEmailAndAudience finds a user with the matching email and audience.
func FindUserByID ¶
FindUserByID finds a user matching the provided ID.
func FindUserByInstanceIDAndID ¶
FindUserByInstanceIDAndID finds a user matching the provided ID.
func FindUserByRecoveryToken ¶
func FindUserByRecoveryToken(tx *storage.Connection, token string) (*User, error)
FindUserByRecoveryToken finds a user with the matching recovery token.
func FindUsersInAudience ¶
func FindUsersInAudience(tx *storage.Connection, instanceID uuid.UUID, aud string, pageParams *Pagination, sortParams *SortParams, filter string) ([]*User, error)
FindUsersInAudience finds users with the matching audience.
func NewUser ¶
func NewUser(instanceID uuid.UUID, email, password, aud string, userData map[string]interface{}) (*User, error)
NewUser initializes a new user from an email, password and user data.
func (*User) Authenticate ¶
Authenticate a user from a password
func (*User) Confirm ¶
func (u *User) Confirm(tx *storage.Connection) error
Confirm resets the confimation token and the confirm timestamp
func (*User) ConfirmEmailChange ¶
func (u *User) ConfirmEmailChange(tx *storage.Connection) error
ConfirmEmailChange confirm the change of email for a user
func (*User) IsConfirmed ¶
IsConfirmed checks if a user has already being registered and confirmed.
func (*User) Recover ¶
func (u *User) Recover(tx *storage.Connection) error
Recover resets the recovery token
func (*User) SetRole ¶
func (u *User) SetRole(tx *storage.Connection, roleName string) error
SetRole sets the users Role to roleName
func (*User) UpdateAppMetaData ¶
func (u *User) UpdateAppMetaData(tx *storage.Connection, updates map[string]interface{}) error
UpdateAppMetaData updates all app data from a map of updates
func (*User) UpdatePassword ¶
func (u *User) UpdatePassword(tx *storage.Connection, password string) error
func (*User) UpdateUserMetaData ¶
func (u *User) UpdateUserMetaData(tx *storage.Connection, updates map[string]interface{}) error
UpdateUserMetaData sets all user data from a map of updates, ensuring that it doesn't override attributes that are not in the provided map.
type UserNotFoundError ¶
type UserNotFoundError struct{}
UserNotFoundError represents when a user is not found.
func (UserNotFoundError) Error ¶
func (e UserNotFoundError) Error() string