feat: Add email validation
All checks were successful
Build Docker / Build Image (push) Successful in 31s

This commit is contained in:
Nathan Woodburn 2023-11-08 14:49:08 +11:00
parent 93f45eec12
commit 5e6af2bcc8
Signed by: nathanwoodburn
GPG Key ID: 203B000478AD0EF1
2 changed files with 12 additions and 2 deletions

10
main.py
View File

@ -6,6 +6,7 @@ import gift
import json import json
import schedule import schedule
import time import time
from email_validator import validate_email, EmailNotValidError
app = Flask(__name__) app = Flask(__name__)
@ -36,7 +37,6 @@ def index():
resp = make_response(render_template('index.html', hidden=params['r'],address=address)) resp = make_response(render_template('index.html', hidden=params['r'],address=address))
resp.set_cookie('r', params['r'], max_age=60*60*24) resp.set_cookie('r', params['r'], max_age=60*60*24)
return resp return resp
return render_template('index.html',address=address) return render_template('index.html',address=address)
@ -59,6 +59,14 @@ def submit():
if 'r' in request.cookies: if 'r' in request.cookies:
hidden = request.cookies['r'] 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) status = gift.gift(name, email, hidden, ip)
print(status,flush=True) print(status,flush=True)

View File

@ -4,3 +4,5 @@ gunicorn
requests requests
pyotp pyotp
schedule schedule
email-validator
py3dns