Skip to content

Commit

Permalink
add duplicate submission check
Browse files Browse the repository at this point in the history
  • Loading branch information
tobru committed Sep 19, 2024
1 parent 143f21a commit dbe0374
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contactform/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,33 @@ class ConfigForm(FlaskForm):
submit = SubmitField("Save Changes")


def is_duplicate_submission(email, csv_file_path):
"""Check if the email has already been submitted."""
try:
with open(csv_file_path, mode="r") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
if row["Email"] == email:
return True
except FileNotFoundError:
# If the CSV file does not exist, treat as no duplicates
pass
return False


@app.route("/", methods=["GET", "POST"])
def index():
form = LeadForm()

if form.validate_on_submit():
# Check if the form submission is a duplicate
if is_duplicate_submission(form.email.data, config.CSV_FILE_PATH):
flash(
"You have already submitted the form. Duplicate submissions are not allowed.",
"warning",
)
return redirect(url_for("index"))

# Generate a random voucher code for APPUiO
voucher_code = random_word(6)

Expand Down

0 comments on commit dbe0374

Please sign in to comment.