diff options
author | Galen Guyer <galen@galenguyer.com> | 2022-07-28 08:12:58 -0400 |
---|---|---|
committer | Galen Guyer <galen@galenguyer.com> | 2022-07-28 10:36:10 -0400 |
commit | a027b5e5e9d1ff43e92ffda42b9d78324e981237 (patch) | |
tree | 11e58c844f7b6cf0ef8e06c5c5fe8d07fba406e9 | |
parent | ba397e55df4ebb0116186e0a70823db3e746c074 (diff) |
Don't let people make votes for options that don't exist
-rw-r--r-- | main.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -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 +} |