handlers

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2021 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package handlers contains the handler for all the HTTP request on the server.

Types and functions whose name ends with "Handler" are the handlers. Types whose name ends with "Query" are the types of the information received in the requests. Types whose name ends with "Answer" are the types of the information sent in the responses.

Handlers are either handler functions (of type server.HandleFunction), or factories for handler objects (of type server.Handler).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigHandler

func ConfigHandler(ctx context.Context, response server.Response, request *server.Request)

ConfigHandler sends the "frontend" section of the configuration file.

func ConfirmHandler

func ConfirmHandler() confirmHandler

ConfirmHandler handles confirmations.

func CountInfoHandler

func CountInfoHandler(ctx context.Context, response server.Response, request *server.Request)

CountInfoEntry sends the plurality result of a previous round.

func CreateHandler

func CreateHandler(evtManager events.Manager) createHandler

CreateHandler creates a new poll.

func DeleteHandler

func DeleteHandler(evtManager events.Manager) deleteHandler

DeleteHandler deletes a poll.

func ForgotHandler added in v0.1.5

func ForgotHandler(evtManager events.Manager) forgotHandler

ForgotHandler handles requests to change a user password when the user has forgotten the current password.

func LaunchHandler added in v0.1.6

func LaunchHandler(evtManager events.Manager) launchHandler

LaunchHandler forces the start of a waiting poll.

func ListHandler

func ListHandler(ctx context.Context, response server.Response, request *server.Request)

ListHandler lists the available polls.

func LoginHandler

func LoginHandler(ctx context.Context, response server.Response, request *server.Request)

LoginHandler starts a new session for an existing user.

func PasswdHandler added in v0.1.5

func PasswdHandler(ctx context.Context, response server.Response, request *server.Request)

PasswdHandler changes the password of an existing user. The request must reference a valid confirmation of type passwd.

func PollHandler

func PollHandler(ctx context.Context, response server.Response, request *server.Request)

PollHandler provides general information about a poll.

func PollNotifHandler

func PollNotifHandler(notifChannel services.PollNotifChannel) *pollNotifHandler

PollNotifHandler retrieves the current list of notifications for the user. The same notification may be listed in more than one consecutive answers.

func RefreshHandler

func RefreshHandler(ctx context.Context, response server.Response, request *server.Request)

RefreshHandler creates a fresh new session from an older active session.

func ReverifyHandler

func ReverifyHandler(evtManager events.Manager) reverifyHandler

ReverifyHandler requests the email address of the current user to be verified.

func ShortURLHandler added in v0.1.7

func ShortURLHandler(ctx context.Context, response server.Response, request *server.Request)

ShortURLHandler handles shortcut URL of polls, redirecting to the virtual URL of the poll.

func SignupHandler

func SignupHandler(evtManager events.Manager) signupHandler

SignupHandler creates a new user. On success, a new session is started.

func UninominalBallotHandler

func UninominalBallotHandler(ctx context.Context, response server.Response, request *server.Request)

UninominalBallotAnswer sends the previous ballot (if any), the current one (if any) and all the alternatives.

func UninominalVoteHandler

func UninominalVoteHandler(evtManager events.Manager) uninominalVoteHandler

UninominalVoteHandler votes for an alternative. Blank votes are also permitted.

Types

type BallotType

type BallotType uint8
const (
	BallotTypeClosed BallotType = iota
	BallotTypeUninominal
)

type ConfigAnswer

type ConfigAnswer struct {
	DemoPollSegment string
}

type ConfirmAnswer

type ConfirmAnswer struct {
	Type db.ConfirmationType
}

type CountInfoAnswer

type CountInfoAnswer struct {
	Result []CountInfoEntry
}

type CountInfoEntry

type CountInfoEntry struct {
	Alternative PollAlternative
	Count       uint32
}

type CreatePollElectorate added in v0.1.7

type CreatePollElectorate int8
const (
	CreatePollElectorateAll CreatePollElectorate = iota - 1
	CreatePollElectorateLogged
	CreatePollElectorateVerified
)

func (CreatePollElectorate) ToDB added in v0.1.7

func (self CreatePollElectorate) ToDB() db.Electorate

type CreateQuery

type CreateQuery struct {
	Title            string
	Description      string
	Hidden           bool
	Electorate       CreatePollElectorate
	Start            time.Time
	Alternatives     []SimpleAlternative
	ReportVote       bool
	MinNbRounds      uint8
	MaxNbRounds      uint8
	Deadline         time.Time
	MaxRoundDuration uint64 // milliseconds
	RoundThreshold   float64
	ShortURL         string
}

type InformationType

type InformationType uint8
const (
	InformationTypeNoneYet InformationType = iota
	InformationTypeCounts
)

type ListAnswer

type ListAnswer struct {
	Public []listAnswerEntry
	Own    []listAnswerEntry
}

type NuDate

type NuDate sql.NullTime

NuDate is a marshalable version of sql.NullTime.

func (NuDate) MarshalJSON

func (self NuDate) MarshalJSON() ([]byte, error)

func (*NuDate) UnmarshalJSON

func (self *NuDate) UnmarshalJSON(raw []byte) (err error)

type PollAction

type PollAction uint8
const (
	PollActionVote PollAction = iota
	PollActionModif
	PollActionPart
	PollActionTerm
	PollActionWait
)

type PollAlternative

type PollAlternative struct {
	Id   uint8
	Name string
	Cost float64
}

type PollAnswer

type PollAnswer struct {
	Title            string
	Description      string
	Admin            string
	CreationTime     time.Time
	CurrentRound     uint8
	Active           bool
	State            string
	CarryForward     bool
	Start            time.Time
	RoundDeadline    time.Time
	PollDeadline     time.Time
	MaxRoundDuration uint64 // in milliseconds
	MinNbRounds      uint8
	MaxNbRounds      uint8
	Ballot           BallotType
	Information      InformationType
}

type PollInfo

type PollInfo struct {
	Id           uint32
	NbChoices    uint8
	Active       bool
	CurrentRound uint8
	Public       bool

	Logged      bool
	Participate bool
}

PollInfo holds information on a poll as returned by checkPollAccess.

func (PollInfo) BallotType

func (pollInfo PollInfo) BallotType() BallotType

func (PollInfo) InformationType

func (pollInfo PollInfo) InformationType() InformationType

type PollNotifAnswerEntry

type PollNotifAnswerEntry struct {
	Timestamp time.Time
	Segment   string
	Title     string
	Round     uint8
	Action    services.PollNotifAction
}

type PollNotifQuery

type PollNotifQuery struct {
	LastUpdate time.Time
}

type ProfileInfo

type ProfileInfo struct {
	Verified bool
}

type SimpleAlternative

type SimpleAlternative struct {
	Name string
	Cost float64
}

type UninominalBallotAnswer

type UninominalBallotAnswer struct {
	Previous     uninominalBallot
	Current      uninominalBallot
	Alternatives []PollAlternative
}

UninominalBallotAnswer represents the response sent by UninominalBallotHandler. The fields Previous and Current are not sent in the JSON representation if the user did not vote. If the user abstained, these fields are replaced with fields PreviousIsBlank or CurrentIsBlank with the boolean value true.

func (*UninominalBallotAnswer) MarshalJSON

func (self *UninominalBallotAnswer) MarshalJSON() (ret []byte, err error)

MarshalJSON implements json.Marshaler.

type UninominalVoteQuery

type UninominalVoteQuery struct {
	Blank       bool `json:",omitempty"`
	Alternative uint8
	Round       uint8
}

Jump to

Keyboard shortcuts

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