aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGalen Guyer <galen@galenguyer.com>2022-07-28 08:12:58 -0400
committerGalen Guyer <galen@galenguyer.com>2022-07-28 10:36:10 -0400
commita027b5e5e9d1ff43e92ffda42b9d78324e981237 (patch)
tree11e58c844f7b6cf0ef8e06c5c5fe8d07fba406e9
parentba397e55df4ebb0116186e0a70823db3e746c074 (diff)
Don't let people make votes for options that don't exist
-rw-r--r--main.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/main.go b/main.go
index b78de27..4e00a82 100644
--- a/main.go
+++ b/main.go
@@ -183,6 +183,10 @@ func main() {
return
}
+ if !hasOption(poll, c.PostForm("option")) {
+ c.JSON(500, gin.H{"error": err.Error()})
+ }
+
vote := &database.Vote{
Id: "",
PollId: pId,
@@ -305,3 +309,12 @@ func containsPoll(polls []*database.Poll, poll *database.Poll) bool {
}
return false
}
+
+func hasOption(poll *database.Poll, option string) bool {
+ for _, opt := range poll.Options {
+ if opt == option {
+ return true
+ }
+ }
+ return false
+}