hmm

package
v0.0.0-...-c266842 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Row
	FirstName                 string `db:"first_name"`
	LastName                  string `db:"last_name"`
	DOB                       time.Time
	Gender                    *string
	Active                    bool
	FailedLoginsCount         int64   `db:"failed_logins_count"`
	DoorCode                  *string `db:"door_code"`
	PassHash                  string
	Email                     string
	ConfirmedEmail            bool       `db:"confirmed_email"`
	PhoneNumber               *string    `db:"phone_number"`
	ConfirmedPhone            bool       `db:"confirmed_phone"`
	ZipCode                   string     `db:"zip_code"`
	ReviewTime                *time.Time `db:"review_time"` // timestamp of when the account was reviewed
	ExternalPaymentCustomerID *int64     `db:"external_payment_customer_id"`

	// fields to populate
	Roles Roles
}

Account represents a user account

type AccountRole

type AccountRole struct {
	Row
	AccountID int64 `db:"account_id"`
	RoleID    int64 `db:"role_id"`
}

type AccountService

type AccountService interface {
	Create(ctx context.Context, a *Account, password, confirmationCode string) (*Account, *Confirmation, error)
	Account(id int64) (*Account, error)
	Accounts() (Accounts, error)
	PopulateAccount(a *Account) *Account
	PopulateAccounts(as Accounts) Accounts
}

type Accounts

type Accounts []*Account

type AddAccountRoleReq

type AddAccountRoleReq struct {
	AccountID, RoleID int64
}

type ConfirmEmailRequest

type ConfirmEmailRequest struct {
	ConfirmationKey string
}

type Confirmation

type Confirmation struct {
	Row
	Type                     ConfirmationType
	AccountID                int64 `db:"account_id"`
	Key                      string
	ConfirmationTarget       *string    `db:"confirmation_target"`
	FailedConfirmationsCount int64      `db:"failed_confirmations_count"`
	ConfirmTime              *time.Time `db:"confirm_time"`
	ExpireTime               *time.Time `db:"expire_time"`
}

type ConfirmationService

type ConfirmationService interface {
	PendingConfirmationByKey(key string) (*Confirmation, error)
	Confirm(id int64) (*Confirmation, error)
	FailedConfirmationIncrease(id int64) (*Confirmation, error)
}

type ConfirmationType

type ConfirmationType int
const (
	ConfirmationTypeEmail ConfirmationType = iota
	ConfirmationTypePhone
	ConfirmationTypePasswordReset
)

type CreateRoleReq

type CreateRoleReq struct {
	Name string
}

type EditRoleReq

type EditRoleReq struct {
	Name        *string
	Permissions []string
}

type LoginCredentials

type LoginCredentials struct {
	Email    string
	Password string
}

type ResetPasswordRequest

type ResetPasswordRequest struct {
	Email string
}

type Role

type Role struct {
	Row
	Name           string
	PermissionsBit RolePermission `db:"permission_bit"`

	// Synthetic field
	Permissions []string
}

func (Role) HasPermission

func (r Role) HasPermission(permission RolePermission) bool

HasPermission reports whether a role has the given permission

func (*Role) Populate

func (r *Role) Populate() *Role

Populate populates synthetic fields for the role structure

type RolePermission

type RolePermission int
const (
	PermissionAccountsView RolePermission = 1 << iota
	PermissionAccountsEdit
	PermissionAccountsDeactivate
	PermissionAuthorizationsView
	PermissionAuthorizationsCreate
	PermissionAuthorizationsEdit
	PermissionAuthorizationsDelete
	PermissionRolesView
	PermissionRolesCreate
	PermissionRolesEdit
	PermissionRolesDelete
	LastPermission
)

func StringToRolePermission

func StringToRolePermission(s string) RolePermission

func (RolePermission) Int

func (rp RolePermission) Int() int

func (RolePermission) String

func (r RolePermission) String() string

type RoleService

type RoleService interface {
	Role(id int64) (*Role, error)
	Roles() (Roles, error)
	RolesForAccount(id int64) (Roles, error)
	Create(name string) (*Role, error)
	Update(id int64, permissionBit int) (*Role, error)
	AddRoleToAccount(accountID, roleID int64) (*AccountRole, error)
}

type Roles

type Roles []*Role

func (Roles) Populate

func (rs Roles) Populate() Roles

Populate populates synthetic fields for role structures

type Row

type Row struct {
	ID         int64     `json:"Id"`
	CreateTime time.Time `db:"create_time"`
	UpdateTime time.Time `db:"update_time"`
}

type Session

type Session struct {
	Row
	AccountID        int64     `db:"account_id"`
	Token            string    `db:"token"`
	LastActivityTime time.Time `db:"last_activity_time"`
	ExpirationTime   time.Time `db:"expiration_time"`
}

Session represents an account session

func (Session) View

func (s Session) View(options map[string]bool) SessionView

type SessionService

type SessionService interface {
	Create(ctx context.Context, email, password string) (*Session, error)
	SessionFromToken(token string) (*Session, error)
	ExpireSession(token string) (*Session, error)
	UpdateSession(token string) (*Session, error)
}

type SessionView

type SessionView struct {
	AccountID        int64
	LastActivityTime time.Time
	ExpirationTime   time.Time
}

Jump to

Keyboard shortcuts

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