account

package
v2.7.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// AccountActive indicates a confirmed account with a valid login & authorization
	AccountActive = 1
	// AccountLoggedOut indicates a confirmed account that is not logged in
	AccountLoggedOut = 0

	// AccountDeactivated indicates an account that has been deactivated due to e.g. account deletion or UserID swap
	AccountDeactivated = -1
	// AccountBlocked signals an issue with the account that needs intervention
	AccountBlocked = -2
	// AccountUnconfirmed well guess what?
	AccountUnconfirmed = -3
)

Variables

View Source
var (
	// ErrAccountExists indicates that the account already exists and can't be created
	ErrAccountExists = errors.New("account exists")
	// ErrNoSuchAccount indicates that the account does not exist
	ErrNoSuchAccount = errors.New("no such account")
)

Functions

func AccountLoaderFunc added in v2.5.0

func AccountLoaderFunc(ctx context.Context, key string) (interface{}, error)

AccountLoaderFunc implements the LoaderFunc interface for retrieving account resources

func UpdateAccount

func UpdateAccount(ctx context.Context, account *Account) error

Types

type Account

type Account struct {
	Realm    string `json:"realm"`     // KEY
	UserID   string `json:"user_id"`   // KEY external id for the entity e.g. email for a user
	ClientID string `json:"client_id"` // a unique id within [realm,user_id]
	// status and other metadata
	Status int `json:"status"` // default == AccountUnconfirmed
	// login auditing
	LastLogin  int64  `json:"-"`
	LoginCount int    `json:"-"`
	LoginFrom  string `json:"-"`
	// internal
	Token     string `json:"-"` // a temporary token to confirm the account or to exchanged for the "real" token
	Expires   int64  `json:"-"` // 0 == never
	Confirmed int64  `json:"-"`
	Created   int64  `json:"-"`
	Updated   int64  `json:"-"`
}

Account represents an account for a user or client (e.g. API, bot)

func CreateAccount

func CreateAccount(ctx context.Context, realm, userID string, expires int) (*Account, error)

CreateAccount creates an new account in the given realm. userID has to be unique and a new clientID will be assigned.

func DeleteAccount added in v2.5.0

func DeleteAccount(ctx context.Context, realm, clientID string) (*Account, error)

func FindAccountByToken

func FindAccountByToken(ctx context.Context, token string) (*Account, error)

FindAccountByToken retrieves an account bases on either the temporary token or the auth token

func FindAccountByUserID

func FindAccountByUserID(ctx context.Context, realm, userID string) (*Account, error)

FindAccountUserID retrieves an account bases on the user id

func LookupAccount

func LookupAccount(ctx context.Context, realm, clientID string) (*Account, error)

LookupAccount retrieves an account within a given realm

func ResetAccountChallenge

func ResetAccountChallenge(ctx context.Context, acc *Account, expires int) (*Account, error)

ResetAccountChallenge creates a new confirmation token and resets the timer

func ResetTemporaryToken added in v2.4.0

func ResetTemporaryToken(ctx context.Context, acc *Account, expires int) (*Account, error)

ResetTemporaryToken creates a new temporary token and resets the timer

func (*Account) Equal added in v2.5.0

func (acc *Account) Equal(a *Account) bool

func (*Account) Key added in v2.5.0

func (acc *Account) Key() string

Jump to

Keyboard shortcuts

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