From 5e6af2bcc8215b253fc9693cab414fab32dcbe61 Mon Sep 17 00:00:00 2001 From: Nathan Woodburn Date: Wed, 8 Nov 2023 14:49:08 +1100 Subject: [PATCH] feat: Add email validation --- main.py | 10 +++++++++- requirements.txt | 4 +++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index f7ae3da..d5c056a 100644 --- a/main.py +++ b/main.py @@ -6,6 +6,7 @@ import gift import json import schedule import time +from email_validator import validate_email, EmailNotValidError app = Flask(__name__) @@ -36,7 +37,6 @@ def index(): resp = make_response(render_template('index.html', hidden=params['r'],address=address)) resp.set_cookie('r', params['r'], max_age=60*60*24) return resp - return render_template('index.html',address=address) @@ -59,6 +59,14 @@ def submit(): if 'r' in request.cookies: hidden = request.cookies['r'] + # Validate email + try: + emailinfo = validate_email(email, check_deliverability=False) + email = emailinfo.normalized + except EmailNotValidError as e: + return render_template('error.html',error='Invalid email address',address=address) + + status = gift.gift(name, email, hidden, ip) print(status,flush=True) diff --git a/requirements.txt b/requirements.txt index d0ab8e7..07a29eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,4 +3,6 @@ python-dotenv gunicorn requests pyotp -schedule \ No newline at end of file +schedule +email-validator +py3dns \ No newline at end of file