summaryrefslogtreecommitdiff
path: root/forms.go
diff options
context:
space:
mode:
authorJan Dittberner <jan@dittberner.info>2017-04-21 02:25:49 +0200
committerJan Dittberner <jan@dittberner.info>2017-04-22 00:14:08 +0200
commit2cac50ee86e70428aa06c99f5e009ceaaf1dbc13 (patch)
treeada4eb330be62598445480b6f40a5633ddfa922f /forms.go
parentb6ad5d8ad327066b21bdb690f5a5017f6bed9740 (diff)
downloadcacert-boardvoting-2cac50ee86e70428aa06c99f5e009ceaaf1dbc13.tar.gz
cacert-boardvoting-2cac50ee86e70428aa06c99f5e009ceaaf1dbc13.tar.xz
cacert-boardvoting-2cac50ee86e70428aa06c99f5e009ceaaf1dbc13.zip
Implement proxy voting
Diffstat (limited to 'forms.go')
-rw-r--r--forms.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/forms.go b/forms.go
index b7b7225..e0d430a 100644
--- a/forms.go
+++ b/forms.go
@@ -92,3 +92,40 @@ func (f *EditDecisionForm) Validate() (bool, *Decision) {
return len(f.Errors) == 0, data
}
+
+type ProxyVoteForm struct {
+ Voter string
+ Vote string
+ Justification string
+ Errors map[string]string
+}
+
+func (f *ProxyVoteForm) Validate() (bool, *Voter, *Vote, string) {
+ f.Errors = make(map[string]string)
+
+ data := &Vote{}
+
+ var voter *Voter
+ if voterId, err := strconv.ParseInt(f.Voter, 10, 64); err != nil {
+ f.Errors["Voter"] = fmt.Sprint("Please choose a valid voter", err)
+ } else if voter, err = GetVoterById(voterId); err != nil {
+ f.Errors["Voter"] = fmt.Sprint("Please choose a valid voter", err)
+ } else {
+ data.VoterId = voter.Id
+ }
+
+ if vote, err := strconv.ParseInt(f.Vote, 10, 8); err != nil {
+ f.Errors["Vote"] = fmt.Sprint("Please choose a valid vote", err)
+ } else if voteChoice, ok := VoteChoices[vote]; !ok {
+ f.Errors["Vote"] = fmt.Sprint("Please choose a valid vote")
+ } else {
+ data.Vote = voteChoice
+ }
+
+ justification := strings.TrimSpace(f.Justification)
+ if len(justification) < 3 {
+ f.Errors["Justification"] = "Please enter at least 3 characters."
+ }
+
+ return len(f.Errors) == 0, voter, data, justification
+}