user

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 7, 2020 License: ISC Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CMSPluginVersion            = "1"
	CMSPluginID                 = "cms"
	CmdNewCMSUser               = "newcmsuser"
	CmdCMSUsersByDomain         = "cmsusersbydomain"
	CmdCMSUsersByContractorType = "cmsusersbycontractortype"
	CmdUpdateCMSUser            = "updatecmsuser"
	CmdCMSUserByID              = "cmsuserbyid"
	CmdCMSUserSubContractors    = "cmsusersubcontractors"
	CmdCMSUsersByProposalToken  = "cmsusersbyproposaltoken"
)
View Source
const VersionSession uint32 = 1

VersionSession is the version of the Session struct.

View Source
const VersionUser uint32 = 1

VersionUser is the version of the User struct.

Variables

View Source
var (
	// ErrSessionNotFound indicates that a user session was not found
	// in the database.
	ErrSessionNotFound = errors.New("no user session found")

	// ErrUserNotFound indicates that a user name was not found in the
	// database.
	ErrUserNotFound = errors.New("user not found")

	// ErrUserExists indicates that a user already exists in the
	// database.
	ErrUserExists = errors.New("user already exists")

	// ErrShutdown is emitted when the database is shutting down.
	ErrShutdown = errors.New("database is shutting down")

	// ErrInvalidPlugin is emitted when a invalid plugin is used.
	ErrInvalidPlugin = errors.New("invalid plugin")

	// ErrInvalidPluginCmd is emitted when an invalid plugin command
	// is used.
	ErrInvalidPluginCmd = errors.New("invalid plugin command")
)

Functions

func EncodeCMSUser

func EncodeCMSUser(u CMSUser) ([]byte, error)

EncodeCMSUser encodes a CMSUser into a JSON byte slice.

func EncodeCMSUserByID

func EncodeCMSUserByID(u CMSUserByID) ([]byte, error)

EncodeCMSUserByID encodes a CMSUserByID into a JSON byte slice.

func EncodeCMSUserByIDReply

func EncodeCMSUserByIDReply(u CMSUserByIDReply) ([]byte, error)

EncodeCMSUserByIDReply encodes a CMSUserByIDReply into a JSON byte slice.

func EncodeCMSUserSubContractors

func EncodeCMSUserSubContractors(u CMSUserSubContractors) ([]byte, error)

EncodeCMSUserSubContractors encodes a CMSUserSubContractors into a JSON byte slice.

func EncodeCMSUserSubContractorsReply

func EncodeCMSUserSubContractorsReply(u CMSUserSubContractorsReply) ([]byte, error)

EncodeCMSUserSubContractorsReply encodes a CMSUserSubContractorsReply into a JSON byte slice.

func EncodeCMSUsersByContractorType

func EncodeCMSUsersByContractorType(u CMSUsersByContractorType) ([]byte, error)

EncodeCMSUsersByContractorType encodes a CMSUsersByContractorType into a JSON byte slice.

func EncodeCMSUsersByContractorTypeReply

func EncodeCMSUsersByContractorTypeReply(u CMSUsersByContractorTypeReply) ([]byte, error)

EncodeCMSUsersByContractorTypeReply encodes a CMSUsersByContractorTypeReply into a JSON byte slice.

func EncodeCMSUsersByDomain

func EncodeCMSUsersByDomain(u CMSUsersByDomain) ([]byte, error)

EncodeCMSUsersByDomain encodes a CMSUsersByDomain into a JSON byte slice.

func EncodeCMSUsersByDomainReply

func EncodeCMSUsersByDomainReply(u CMSUsersByDomainReply) ([]byte, error)

EncodeCMSUsersByDomainReply encodes a CMSUsersByDomainReply into a JSON byte slice.

func EncodeCMSUsersByProposalToken

func EncodeCMSUsersByProposalToken(u CMSUsersByProposalToken) ([]byte, error)

EncodeCMSUsersByProposalToken encodes a CMSUsersByProposalToken into a JSON byte slice.

func EncodeCMSUsersByProposalTokenReply

func EncodeCMSUsersByProposalTokenReply(u CMSUsersByProposalTokenReply) ([]byte, error)

EncodeCMSUsersByProposalTokenReply encodes a CMSUsersByProposalTokenReply into a JSON byte slice.

func EncodeNewCMSUser

func EncodeNewCMSUser(u NewCMSUser) ([]byte, error)

EncodeNewCMSUser encodes a NewCMSUser into a JSON byte slice.

func EncodeNewCMSUserReply

func EncodeNewCMSUserReply(u NewCMSUserReply) ([]byte, error)

EncodeNewCMSUserReply encodes a NewCMSUserReply into a JSON byte slice.

func EncodeSession

func EncodeSession(s Session) ([]byte, error)

EncodeSession encodes Session into a JSON byte slice.

func EncodeUpdateCMSUser

func EncodeUpdateCMSUser(u UpdateCMSUser) ([]byte, error)

EncodeUpdateCMSUser encodes a UpdateCMSUser into a JSON byte slice.

func EncodeUpdateCMSUserReply

func EncodeUpdateCMSUserReply(u UpdateCMSUserReply) ([]byte, error)

EncodeUpdateCMSUserReply encodes a UpdateCMSUserReply into a JSON byte slice.

func EncodeUser

func EncodeUser(u User) ([]byte, error)

EncodeUser encodes User into a JSON byte slice.

Types

type CMSUser

type CMSUser struct {
	User
	Domain             int         `json:"domain"` // Contractor domain
	GitHubName         string      `json:"githubname"`
	MatrixName         string      `json:"matrixname"`
	ContractorType     int         `json:"contractortype"`
	ContractorName     string      `json:"contractorname"`
	ContractorLocation string      `json:"contractorlocation"`
	ContractorContact  string      `json:"contractorcontact"`
	SupervisorUserIDs  []uuid.UUID `json:"supervisoruserids"`
	ProposalsOwned     []string    `json:"proposalsowned"`
}

CMSUser represents a CMS user. It contains the standard politeiawww user fields as well as CMS specific user fields.

func DecodeCMSUser

func DecodeCMSUser(payload []byte) (*CMSUser, error)

DecodeCMSUser decodes a JSON byte slice into a CMSUser.

type CMSUserByID

type CMSUserByID struct {
	ID string `json:"id"` // Contractor user id
}

CMSUserByID returns CMS User with the matching user ID.

func DecodeCMSUserByID

func DecodeCMSUserByID(b []byte) (*CMSUserByID, error)

DecodeCMSUserByID decodes JSON byte slice into a CMSUserByID.

type CMSUserByIDReply

type CMSUserByIDReply struct {
	User *CMSUser `json:"user"`
}

CMSUserByIDReply is the reply to the CMSUserByID command.

func DecodeCMSUserByIDReply

func DecodeCMSUserByIDReply(b []byte) (*CMSUserByIDReply, error)

DecodeCMSUserByIDReply decodes JSON byte slice into a CMSUserByIDReply.

type CMSUserSubContractors

type CMSUserSubContractors struct {
	ID string `json:"id"` // Contractor user id
}

CMSUserSubContractors retrieves all users that are currently have the given ID as their SupervisorID

func DecodeCMSUserSubContractors

func DecodeCMSUserSubContractors(b []byte) (*CMSUserSubContractors, error)

DecodeCMSUserSubContractors decodes JSON byte slice into a CMSUserSubContractors.

type CMSUserSubContractorsReply

type CMSUserSubContractorsReply struct {
	Users []CMSUser `json:"users"`
}

CMSUserSubContractorsReply is the reply to the CMSUserSubContractors command.

func DecodeCMSUserSubContractorsReply

func DecodeCMSUserSubContractorsReply(b []byte) (*CMSUserSubContractorsReply, error)

DecodeCMSUserSubContractorsReply decodes JSON byte slice into a CMSUserSubContractorsReply.

type CMSUsersByContractorType

type CMSUsersByContractorType struct {
	ContractorType int `json:"contractortype"` // Contractor type
}

CMSUsersByContractorType returns all CMS users within the provided contractor type.

func DecodeCMSUsersByContractorType

func DecodeCMSUsersByContractorType(b []byte) (*CMSUsersByContractorType, error)

DecodeCMSUsersByContractorType decodes JSON byte slice into a CMSUsersByContractorType.

type CMSUsersByContractorTypeReply

type CMSUsersByContractorTypeReply struct {
	Users []CMSUser `json:"users"`
}

CMSUsersByContractorTypeReply is the reply to the CMSUsersByContractorType command.

func DecodeCMSUsersByContractorTypeReply

func DecodeCMSUsersByContractorTypeReply(b []byte) (*CMSUsersByContractorTypeReply, error)

DecodeCMSUsersByContractorTypeReply decodes JSON byte slice into a CMSUsersByContractorTypeReply.

type CMSUsersByDomain

type CMSUsersByDomain struct {
	Domain int `json:"domain"` // Contractor domain
}

CMSUsersByDomain returns all CMS users within the provided domain.

func DecodeCMSUsersByDomain

func DecodeCMSUsersByDomain(b []byte) (*CMSUsersByDomain, error)

DecodeCMSUsersByDomain decodes JSON byte slice into a CMSUsersByDomain.

type CMSUsersByDomainReply

type CMSUsersByDomainReply struct {
	Users []CMSUser `json:"users"`
}

CMSUsersByDomainReply is the reply to the CMSUsersByDomain command.

func DecodeCMSUsersByDomainReply

func DecodeCMSUsersByDomainReply(b []byte) (*CMSUsersByDomainReply, error)

DecodeCMSUsersByDomainReply decodes JSON byte slice into a CMSUsersByDomainReply.

type CMSUsersByProposalToken

type CMSUsersByProposalToken struct {
	Token string `json:"token"` // Proposal token
}

CMSUsersByProposalToken returns all CMS users within the provided proposal token.

func DecodeCMSUsersByProposalToken

func DecodeCMSUsersByProposalToken(b []byte) (*CMSUsersByProposalToken, error)

DecodeCMSUsersByProposalToken decodes JSON byte slice into a CMSUsersByProposalToken.

type CMSUsersByProposalTokenReply

type CMSUsersByProposalTokenReply struct {
	Users []CMSUser `json:"users"`
}

CMSUsersByProposalTokenReply is the reply to the CMSUsersByProposalToken command.

func DecodeCMSUsersByProposalTokenReply

func DecodeCMSUsersByProposalTokenReply(b []byte) (*CMSUsersByProposalTokenReply, error)

DecodeCMSUsersByProposalTokenReply decodes JSON byte slice into a CMSUsersByProposalTokenReply.

type Database

type Database interface {
	// Add a new user
	UserNew(User) error

	// Update an existing user
	UserUpdate(User) error

	// Return user record given the username
	UserGetByUsername(string) (*User, error)

	// Return user record given its id
	UserGetById(uuid.UUID) (*User, error)

	// Return user record given a public key
	UserGetByPubKey(string) (*User, error)

	// Return a map of public key to user record
	UsersGetByPubKey(pubKeys []string) (map[string]User, error)

	// Iterate over all users
	AllUsers(callbackFn func(u *User)) error

	// Create or update a user session
	SessionSave(Session) error

	// Return a user session given its id
	SessionGetByID(sessionID string) (*Session, error)

	// Delete a user session given its id
	SessionDeleteByID(sessionID string) error

	// Delete all sessions for a user except for the given session IDs
	SessionsDeleteByUserID(id uuid.UUID, exemptSessionIDs []string) error

	// Register a plugin
	RegisterPlugin(Plugin) error

	// Execute a plugin command
	PluginExec(PluginCommand) (*PluginCommandReply, error)

	// Close performs cleanup of the backend.
	Close() error
}

Database describes the interface used for interacting with the user database.

type Identity

type Identity struct {
	Key         [identity.PublicKeySize]byte `json:"key"`         // ed25519 public key
	Activated   int64                        `json:"activated"`   // Time key as activated for use
	Deactivated int64                        `json:"deactivated"` // Time key was deactivated
}

Identity wraps an ed25519 public key and timestamps to indicate if it is active. An identity can be in one of three states: inactive, active, or deactivated.

inactive: Activated == 0 && Deactivated == 0 The identity has been created, but has not yet been activated.

active: Activated != 0 && Deactivated == 0 The identity has been created and has been activated.

deactivated: Deactivated != 0 The identity in no longer active and the key is no longer valid.

func NewIdentity

func NewIdentity(publicKey string) (*Identity, error)

NewIdentity returns a new inactive identity that was created using the provided public key.

func (*Identity) Activate

func (i *Identity) Activate()

Activate activates the identity by setting the activated timestamp.

func (*Identity) Deactivate

func (i *Identity) Deactivate()

Deactivate deactivates the identity by setting the deactivated timestamp.

func (*Identity) IsActive

func (i *Identity) IsActive() bool

IsActive returns whether the identity is active.

func (*Identity) IsInactive

func (i *Identity) IsInactive() bool

IsInactive returns whether the identity is inactive.

func (*Identity) String

func (i *Identity) String() string

String returns a hex encoded string of the identity key.

type NewCMSUser

type NewCMSUser struct {
	Email                     string `json:"email"`
	Username                  string `json:"username"`
	NewUserVerificationToken  []byte `json:"newuserverificationtoken"`
	NewUserVerificationExpiry int64  `json:"newuserverificationtokenexiry"`
	ContractorType            int    `json:"contractortype"`
}

NewCMSUser creates a new CMS user record in the user database.

func DecodeNewCMSUser

func DecodeNewCMSUser(b []byte) (*NewCMSUser, error)

DecodeNewCMSUser decodes JSON byte slice into a NewCMSUser.

type NewCMSUserReply

type NewCMSUserReply struct{}

NewCMSUserReply is the reply to the NewCMSUser command.

func DecodeNewCMSUserReply

func DecodeNewCMSUserReply(b []byte) (*NewCMSUserReply, error)

DecodeNewCMSUserReply decodes JSON byte slice into a NewCMSUserReply.

type Plugin

type Plugin struct {
	ID       string
	Version  string
	Settings []PluginSetting
}

Plugin describes a plugin and its settings.

type PluginCommand

type PluginCommand struct {
	ID      string // Plugin identifier
	Command string // Command identifier
	Payload string // Command payload
}

PluginCommand is used to execute a plugin command.

type PluginCommandReply

type PluginCommandReply struct {
	ID      string // Plugin identifier
	Command string // Command identifier
	Payload string // Command reply payload
}

PluginCommandReply is used to reply to a PluginCommand.

type PluginSetting

type PluginSetting struct {
	Key   string // Name of setting
	Value string // Value of setting
}

PluginSetting holds the key/value pair of a plugin setting.

type ProposalCredit

type ProposalCredit struct {
	PaywallID       uint64 `json:"paywallid"`       // Proposal paywall ID of associated paywall
	Price           uint64 `json:"price"`           // Credit price in atoms
	DatePurchased   int64  `json:"datepurchased"`   // Unix timestamp of credit purchase
	TxID            string `json:"txid"`            // Payment transaction ID
	CensorshipToken string `json:"censorshiptoken"` // Token of proposal that spent this credit
}

A proposal credit allows the user to submit a new proposal. Credits are created when a user sends a payment to a proposal paywall. A credit is automatically spent when a user submits a new proposal. When a credit is spent, it is updated with the proposal's censorship token and moved to the user's spent proposal credits list.

type ProposalPaywall

type ProposalPaywall struct {
	ID          uint64 `json:"id"`          // Paywall ID
	CreditPrice uint64 `json:"creditprice"` // Cost per proposal credit in atoms
	Address     string `json:"address"`     // Paywall address
	TxNotBefore int64  `json:"txnotbefore"` // Unix timestamp of minimum timestamp for paywall tx
	PollExpiry  int64  `json:"pollexpiry"`  // Unix timestamp of expiration time of paywall polling
	TxID        string `json:"txid"`        // Payment transaction ID
	TxAmount    uint64 `json:"txamount"`    // Amount sent to paywall address in atoms
	NumCredits  uint64 `json:"numcredits"`  // Number of proposal credits created by payment tx
}

A proposal paywall allows the user to purchase proposal credits. Proposal paywalls are only valid for one tx. The number of proposal credits created is determined by dividing the tx amount by the credit price. Proposal paywalls expire after a set duration. politeiawww polls the paywall address for a payment tx until the paywall is either paid or it expires.

type Session

type Session struct {
	ID        string    `json:"id"`        // Unique session ID
	UserID    uuid.UUID `json:"userid"`    // User UUID
	CreatedAt int64     `json:"createdat"` // Created at UNIX timestamp
	Values    string    `json:"values"`    // Encoded session values
}

Session represents a user session.

ID is the decoded session ID. The ID present in the session cookie is the encoded session ID. The encoding/decoding is handled by the session Store.

Values are politeiawww specific encoded session values. The encoding is handled by the session Store.

UserID and CreatedAt are included in the encoded Values but have also been broken out into their own fields so that they can be queryable. UserID allows for lookups by UserID and CreatedAt allows for periodically cleaning up expired sessions in the database.

func DecodeSession

func DecodeSession(payload []byte) (*Session, error)

DecodeSession decodes a JSON byte slice into a Session.

type UpdateCMSUser

type UpdateCMSUser struct {
	ID                 uuid.UUID   `json:"id"`
	Domain             int         `json:"domain"` // Contractor domain
	GitHubName         string      `json:"githubname"`
	MatrixName         string      `json:"matrixname"`
	ContractorType     int         `json:"contractortype"`
	ContractorName     string      `json:"contractorname"`
	ContractorLocation string      `json:"contractorlocation"`
	ContractorContact  string      `json:"contractorcontact"`
	SupervisorUserIDs  []uuid.UUID `json:"supervisoruserids"`
	ProposalsOwned     []string    `json:"proposalsowned"`
}

UpdateCMSUser creates a new CMS user record in the user database.

func DecodeUpdateCMSUser

func DecodeUpdateCMSUser(b []byte) (*UpdateCMSUser, error)

DecodeUpdateCMSUser decodes JSON byte slice into a UpdateCMSUser.

type UpdateCMSUserReply

type UpdateCMSUserReply struct{}

UpdateCMSUserReply is the reply to the UpdateCMSUser command.

func DecodeUpdateCMSUserReply

func DecodeUpdateCMSUserReply(b []byte) (*UpdateCMSUserReply, error)

DecodeUpdateCMSUserReply decodes JSON byte slice into a UpdateCMSUserReply.

type User

type User struct {
	ID                  uuid.UUID `json:"id"`                  // Unique user uuid
	Email               string    `json:"email"`               // Email address
	Username            string    `json:"username"`            // Unique username
	HashedPassword      []byte    `json:"hashedpassword"`      // Blowfish hash
	Admin               bool      `json:"admin"`               // Is user an admin
	EmailNotifications  uint64    `json:"emailnotifications"`  // Email notification setting
	LastLoginTime       int64     `json:"lastlogintime"`       // Unix timestamp of last login
	FailedLoginAttempts uint64    `json:"failedloginattempts"` // Sequential failed login attempts
	Deactivated         bool      `json:"deactivated"`         // Is account deactivated

	// Verification tokens and their expirations
	NewUserVerificationToken        []byte `json:"newuserverificationtoken"`
	NewUserVerificationExpiry       int64  `json:"newuserverificationtokenexiry"`
	ResendNewUserVerificationExpiry int64  `json:"resendnewuserverificationtoken"`
	UpdateKeyVerificationToken      []byte `json:"updatekeyverificationtoken"`
	UpdateKeyVerificationExpiry     int64  `json:"updatekeyverificationexpiry"`
	ResetPasswordVerificationToken  []byte `json:"resetpasswordverificationtoken"`
	ResetPasswordVerificationExpiry int64  `json:"resetpasswordverificationexpiry"`

	// PaywallAddressIndex is the index that is used to generate the
	// paywall address for the user. The same paywall address is used
	// for the user registration paywall and for proposal credit
	// paywalls. The index is set during the new user record creation
	// and is sequential.
	// XXX why is this an uint64 when hdkeychain requires a uint32?
	PaywallAddressIndex uint64 `json:"paywalladdressindex"`

	// User registration paywall info
	NewUserPaywallAddress string `json:"newuserpaywalladdress"`
	NewUserPaywallAmount  uint64 `json:"newuserpaywallamount"`
	NewUserPaywallTx      string `json:"newuserpaywalltx"`

	// NewUserPaywallTxNotBeore is the minimum UNIX time (in seconds)
	// required for the block containing the transaction sent to
	// NewUserPaywallAddress. If the user has already paid, this field
	// will be empty.
	NewUserPaywallTxNotBefore int64 `json:"newuserpaywalltxnotbefore"`

	// The UNIX time (in seconds) for when the server will stop polling
	// the server for transactions at NewUserPaywallAddress. If the
	// user has already paid, this field will be empty.
	NewUserPaywallPollExpiry int64 `json:"newuserpaywallpollexpiry"`

	// User access times for proposal comments. The access time is a
	// Unix timestamp of the last time the user accessed a proposal's
	// comments.
	// [token]accessTime
	ProposalCommentsAccessTimes map[string]int64 `json:"proposalcommentsaccesstime"`

	// All identities the user has ever used. We allow the user to change
	// identities to deal with key loss. An identity can be in one of three
	// states: inactive, active, or deactivated.
	//
	// Inactive identities
	// An identity is consider inactive until it has been verified.
	// An unverified user will have an inactive identity.
	// A user will only ever have one inactive identity at a time.
	//
	// Active identities
	// A verified user will always have one active identity.
	// A verified user may have both an active and inactive identity if
	// they have requested a new identity but have not yet verified it.
	//
	// Deactivated identities
	// An identity is deactivated when it is replaced by a new identity.
	// The key of a deactivated identity is no longer valid.
	// An identity cannot be re-activated once it has been deactivated.
	Identities []Identity `json:"identities"`

	// All proposal paywalls that have been issued to the user in chronological
	// order.
	ProposalPaywalls []ProposalPaywall `json:"proposalpaywalls"`

	// All proposal credits that have been purchased by the user, but have not
	// yet been used to submit a proposal.  Once a credit is used to submit a
	// proposal, it is updated with the proposal's censorship token and moved to
	// the user's spent proposal credits list.  The price that the proposal
	// credit was purchased at is in atoms.
	UnspentProposalCredits []ProposalCredit `json:"unspentproposalcredits"`

	// All credits that have been purchased by the user and have already been
	// used to submit proposals.  Spent credits have a proposal censorship token
	// associated with them to signify that they have been spent. The price that
	// the proposal credit was purchased at is in atoms.
	SpentProposalCredits []ProposalCredit `json:"spentproposalcredits"`
}

User represents a politeiawww user.

func DecodeUser

func DecodeUser(payload []byte) (*User, error)

DecodeUser decodes a JSON byte slice into a User.

func (*User) ActivateIdentity

func (u *User) ActivateIdentity(key []byte) error

ActivateIdentity sets the identity associated with the provided key as the active identity for the user. The provided key must correspond to an inactive identity. If there is an existing active identity, it wil be deactivated.

func (*User) ActiveIdentity

func (u *User) ActiveIdentity() *Identity

ActiveIdentity returns the active identity for the user if one exists.

func (*User) AddIdentity

func (u *User) AddIdentity(id Identity) error

AddIdentity adds the provided inactive identity to the identities array for the user. Any existing inactive identities are deactivated. A user should only ever have one inactive identity at a time, but due to a prior bug, this may not always be the case.

func (*User) InactiveIdentity

func (u *User) InactiveIdentity() *Identity

InactiveIdentity returns the inactive identity for the user if one exists.

func (*User) PublicKey

func (u *User) PublicKey() string

PublicKey returns a hex encoded string of the user's active identity.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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