]> git.scottworley.com Git - voter/commitdiff
Disallow voting for eliminated candidates server-side
authorScott Worley <scottworley@scottworley.com>
Sun, 7 Apr 2024 13:12:24 +0000 (06:12 -0700)
committerScott Worley <scottworley@scottworley.com>
Sun, 7 Apr 2024 13:14:42 +0000 (06:14 -0700)
Changelog.md
src/main.rs

index ade0188b0cf56fb915633e6b662321232d4d6e47..9ba73d5f80efc4948b312aeec7c4d97a7fde49c6 100644 (file)
@@ -1,3 +1,8 @@
+# Unreleased
+
+New feature: Eliminated candidates
+
+
 # 0.2.6 (November 23, 2022)
 
 Add license, README, and Changelog
index 1ec9d9c352d41d0d01e259cee2de52df43a70e22..92937e58ff6f9b73a313d554432f695083b99161 100644 (file)
@@ -275,6 +275,13 @@ fn record_vote(dir: &Path, request: &cgi::Request) -> Result<cgi::Response, cgi:
     {
         return Err(cgi::text_response(415, "Invalid vote"));
     }
+    let elim =
+        read_elim_list(dir).map_err(|_| cgi::text_response(503, "Couldn't read eliminations"))?;
+    if elim.contains(
+        std::str::from_utf8(&body[2..]).map_err(|_| cgi::text_response(415, "Vote not UTF-8"))?,
+    ) {
+        return Err(cgi::text_response(403, "Candidate eliminated"));
+    }
     write_vote(dir, get_voter(request)?, body)
         .map_err(|_| cgi::text_response(503, "Couldn't record vote"))?;
     Ok(cgi::text_response(200, "Vote recorded"))