user

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2021 License: ISC Imports: 9 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"
	CmdNewCMSUserCodeStats         = "newcmsusercodestats"
	CmdUpdateCMSUserCodeStats      = "updatecmsusercodestats"
	CmdCMSCodeStatsByUserMonthYear = "cmscodestatsbyusermonthyear"
)
View Source
const (
	// PiUserPluginID is a temporary plugin ID for user functionality
	// that is specific to pi.
	PiUserPluginID = "piuser"

	// ErrorCodeInvalid is an invalid error code.
	ErrorCodeInvalid = 0

	// ErrorCodeUserRegistrationNotPaid is returned when a user
	// attempts to write data to politeia prior to paying their user
	// registration fee.
	ErrorCodeUserRegistrationNotPaid = 1

	// ErrorCodeBalanceInsufficient is returned when a user attempts
	// to submit a proposal but does not have a proposal credit.
	ErrorCodeUserBalanceInsufficient = 2
)
View Source
const VersionEmailHistory uint32 = 1

VersionEmailHistory is the version of the EmailHistory struct.

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")

	// ErrCodeStatsNotFound indicates that an requested code stats entry wasn't
	// found.
	ErrCodeStatsNotFound = errors.New("code stats not found")
)
View Source
var (
	// ErrorCodes contains the human readable error codes.
	ErrorCodes = map[int]string{
		ErrorCodeInvalid:                 "error code invalid",
		ErrorCodeUserRegistrationNotPaid: "user registration not paid",
		ErrorCodeUserBalanceInsufficient: "user balance insufficient",
	}
)

Functions

func EncodeCMSCodeStatsByUserMonthYear

func EncodeCMSCodeStatsByUserMonthYear(u CMSCodeStatsByUserMonthYear) ([]byte, error)

EncodeCMSCodeStatsByUserMonthYear encodes a CMSCodeStatsByUserMonthYear into a JSON byte slice.

func EncodeCMSCodeStatsByUserMonthYearReply

func EncodeCMSCodeStatsByUserMonthYearReply(u CMSCodeStatsByUserMonthYearReply) ([]byte, error)

EncodeCMSCodeStatsByUserMonthYearReply encodes a CMSCodeStatsByUserMonthYearReply into a JSON byte slice.

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 EncodeCodeStats

func EncodeCodeStats(cs CodeStats) ([]byte, error)

EncodeCodeStats encodes a CodeStats into a JSON byte slice.

func EncodeNewCMSCodeStats

func EncodeNewCMSCodeStats(u NewCMSCodeStats) ([]byte, error)

EncodeNewCMSCodeStats encodes a NewCMSCodeStats into a JSON byte slice.

func EncodeNewCMSCodeStatsReply

func EncodeNewCMSCodeStatsReply(u NewCMSCodeStatsReply) ([]byte, error)

EncodeNewCMSCodeStatsReply encodes a NewCMSCodeStatsReply 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 EncodeUpdateCMSCodeStats

func EncodeUpdateCMSCodeStats(u UpdateCMSCodeStats) ([]byte, error)

EncodeUpdateCMSCodeStats encodes a UpdateCMSCodeStats into a JSON byte slice.

func EncodeUpdateCMSCodeStatsReply

func EncodeUpdateCMSCodeStatsReply(u UpdateCMSCodeStatsReply) ([]byte, error)

EncodeUpdateCMSCodeStatsReply encodes a UpdateCMSCodeStatsReply 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.

func NewTestMailerDB

func NewTestMailerDB(histories map[uuid.UUID]EmailHistory) *testMailerDB

NewTestMailerDB returns a new testMailerDB. The caller can optionally provide a list of email histories to seed the testMailerDB with on intialization.

Types

type CMSCodeStatsByUserMonthYear

type CMSCodeStatsByUserMonthYear struct {
	GithubName string `json:"githubname"`
	Month      int    `json:"month"`
	Year       int    `json:"year"`
}

CMSCodeStatsByUserMonthYear fetches CMS code stats based on requested githubname, month and year

func DecodeCMSCodeStatsByUserMonthYear

func DecodeCMSCodeStatsByUserMonthYear(b []byte) (*CMSCodeStatsByUserMonthYear, error)

DecodeCMSCodeStatsByUserMonthYear decodes JSON byte slice into a CMSCodeStatsByUserMonthYear.

type CMSCodeStatsByUserMonthYearReply

type CMSCodeStatsByUserMonthYearReply struct {
	UserCodeStats []CodeStats `json:"usercodestats"`
}

CMSCodeStatsByUserMonthYearReply replies CMS code stats based on requested githubname, month and year

func DecodeCMSCodeStatsByUserMonthYearReply

func DecodeCMSCodeStatsByUserMonthYearReply(b []byte) (*CMSCodeStatsByUserMonthYearReply, error)

DecodeCMSCodeStatsByUserMonthYearReply decodes JSON byte slice into a CMSCodeStatsByUserMonthYearReply.

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 CodeStats

type CodeStats struct {
	ID               string   // UserID + GithubName + Month + Year
	Repository       string   // Repository
	GitHubName       string   // GithubName
	Month            int      // Month of code stats
	Year             int      // Year of code stats
	PRs              []string // All PR URLs
	Reviews          []string // All Reviewed PR URLS
	Commits          []string // All of the commit URLS
	MergedAdditions  int64    // Total merged code additions
	MergedDeletions  int64    // Total merged code deletions
	UpdatedAdditions int64    // Total updated code additions
	UpdatedDeletions int64    // Total updated code deletions
	ReviewAdditions  int64    // Total reviewed code additions
	ReviewDeletions  int64    // Total reviewed code deletions
	CommitAdditions  int64    // Total committed code additions
	CommitDeletions  int64    // Total committed code deletions
}

CodeStats is contains the all the information about a given user's code work underneath a given repository over a certain month/year.

func DecodeCodeStats

func DecodeCodeStats(b []byte) (*CodeStats, error)

DecodeCodeStats decodes JSON byte slice into a CodeStats.

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)

	// Insert a user to the database.
	// Intended to be used for migration between databases.
	InsertUser(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

	// SetPaywallAddressIndex updates the paywall address index.
	SetPaywallAddressIndex(index uint64) error

	// Rotate encryption keys
	RotateKeys(newKeyPath 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 EmailHistory

type EmailHistory struct {
	Timestamps []int64 `json:"timestamps"` // Received email UNIX ts

	// LimitWarningSent is used to track users that have hit the rate
	// limit and have already been sent a notification email letting
	// them know that they hit the rate limit.
	LimitWarningSent bool `json:"limitwarningsent"`
}

EmailHistory keeps track of the received emails by each user. This is used to rate limit the amount of emails an user can receive in a 24h time window. This was not stored in the user object in order to avoid race conditions on db calls, since our user db currently does not support transactions, and email notifications run in a separate goroutine. This workaround won't be necessary once the user layer gets rewritten.

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 MailerDB

type MailerDB interface {
	// EmailHistoriesSave saves the provided email histories to the
	// database. The histories map contains map[userid]EmailHistory.
	EmailHistoriesSave(histories map[uuid.UUID]EmailHistory) error

	// EmailHistoriesGet retrieves the email histories for the provided
	// user IDs. The returned map[userid]EmailHistory will contain an
	// entry for each of the provided user ID. If a provided user ID
	// does not correspond to a user in the database then the entry will
	// be skipped in the returned map. An error is not returned.
	EmailHistoriesGet(users []uuid.UUID) (map[uuid.UUID]EmailHistory, error)
}

MailerDB describes the interface used to interact with the email histories table from the user database, used by the mail client.

type NewCMSCodeStats

type NewCMSCodeStats struct {
	UserCodeStats []CodeStats `json:"usercodestats"`
}

NewCMSCodeStats creates a new CMS code stats record in the user database.

func DecodeNewCMSCodeStats

func DecodeNewCMSCodeStats(b []byte) (*NewCMSCodeStats, error)

DecodeNewCMSCodeStats decodes JSON byte slice into a NewCMSCodeStats.

type NewCMSCodeStatsReply

type NewCMSCodeStatsReply struct{}

NewCMSCodeStatsReply replies a to a NewCMSCodeStats request

func DecodeNewCMSCodeStatsReply

func DecodeNewCMSCodeStatsReply(b []byte) (*NewCMSCodeStatsReply, error)

DecodeNewCMSCodeStatsReply decodes JSON byte slice into a NewCMSCodeStatsReply.

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 UpdateCMSCodeStats

type UpdateCMSCodeStats struct {
	UserCodeStats []CodeStats `json:"usercodestats"`
}

UpdateCMSCodeStats updates a CMS code stats record in the user database.

func DecodeUpdateCMSCodeStats

func DecodeUpdateCMSCodeStats(b []byte) (*UpdateCMSCodeStats, error)

DecodeUpdateCMSCodeStats decodes JSON byte slice into a UpdateCMSCodeStats.

type UpdateCMSCodeStatsReply

type UpdateCMSCodeStatsReply struct{}

UpdateCMSCodeStatsReply replies a to a UpdateCMSCodeStats request

func DecodeUpdateCMSCodeStatsReply

func DecodeUpdateCMSCodeStatsReply(b []byte) (*UpdateCMSCodeStatsReply, error)

DecodeUpdateCMSCodeStatsReply decodes JSON byte slice into a UpdateCMSCodeStatsReply.

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"`

	// TOTP Secret Key and type of TOTP being used.
	TOTPSecret             string  `json:"totpsecret"`
	TOTPType               int     `json:"totptype"`
	TOTPVerified           bool    `json:"totpverified"` // whether current totp secret has been verified with
	TOTPLastUpdated        []int64 `json:"totplastupdated"`
	TOTPLastFailedCodeTime []int64 `json:"totplastfailedcodetime"`
}

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) NotificationIsEnabled

func (u *User) NotificationIsEnabled(ntfnBit uint64) bool

NotificationIsEnabled returns whether the user has the provided notification bit enabled. This function will always return false if the user has been deactivated.

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