update captcha and send email to user
This commit is contained in:
parent
4988092706
commit
a1f602d313
@ -5,5 +5,7 @@ db_path = /tmp/contact-form.db
|
|||||||
captcha_timout = 3600
|
captcha_timout = 3600
|
||||||
|
|
||||||
[email]
|
[email]
|
||||||
|
sender = email@example.com
|
||||||
reciever = email@example.com
|
reciever = email@example.com
|
||||||
server = localhost
|
server = localhost
|
||||||
|
subject = contact to katzei
|
@ -5,24 +5,6 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<link rel="stylesheet" href="/css/frombulma.css">
|
<link rel="stylesheet" href="/css/frombulma.css">
|
||||||
<link rel="stylesheet" href="/css/styles.css">
|
<link rel="stylesheet" href="/css/styles.css">
|
||||||
<style type="text/css">
|
|
||||||
.form-line>.input, .form-line>.textarea{
|
|
||||||
border-color: #aaaaaa;
|
|
||||||
width:100%;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
|
||||||
.form-line>.textarea{
|
|
||||||
min-height: 25em;
|
|
||||||
}
|
|
||||||
.form-error{
|
|
||||||
width: 100%;
|
|
||||||
border-radius: 4px;
|
|
||||||
margin-bottom: 1em;
|
|
||||||
}
|
|
||||||
.form-alert{
|
|
||||||
background-color: rgba(255, 0, 0, 0.2);
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
@ -44,7 +26,7 @@
|
|||||||
<label class="label" for="captcha">Vérification d’humanité: combien font {{first_number}} {{op_text}} {{second_number}} ?</label>
|
<label class="label" for="captcha">Vérification d’humanité: combien font {{first_number}} {{op_text}} {{second_number}} ?</label>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-line field">
|
<div class="form-line field">
|
||||||
<input class="input {% if captcha_error %}form-alert{% endif %}" id="captcha" type="number" name="captcha" min="-10" max="100" required />
|
<input class="input {% if captcha_error %}form-alert{% endif %}" id="captcha" type="number" name="captcha" min="0" max="81" required />
|
||||||
</div>
|
</div>
|
||||||
{% if captcha_error %}
|
{% if captcha_error %}
|
||||||
<div class="form-error">Le captcha est invalide veuillez réessayer</div>
|
<div class="form-error">Le captcha est invalide veuillez réessayer</div>
|
||||||
|
24
webapp.py
24
webapp.py
@ -52,6 +52,8 @@ def generate_captacha():
|
|||||||
first_number = random.randrange(10)
|
first_number = random.randrange(10)
|
||||||
second_number = random.randrange(10)
|
second_number = random.randrange(10)
|
||||||
op_text, op_func = random.choice(OPERATORS)
|
op_text, op_func = random.choice(OPERATORS)
|
||||||
|
if op_text == "-" and first_number < second_number:
|
||||||
|
first_number, second_number = second_number, first_number
|
||||||
result = op_func(first_number, second_number)
|
result = op_func(first_number, second_number)
|
||||||
captcha = Captcha(
|
captcha = Captcha(
|
||||||
token=token_urlsafe(67),
|
token=token_urlsafe(67),
|
||||||
@ -81,14 +83,24 @@ def validate_captcha(token, value):
|
|||||||
|
|
||||||
|
|
||||||
def send_email(sender, message):
|
def send_email(sender, message):
|
||||||
email = EmailMessage()
|
katzei_email = EmailMessage()
|
||||||
email.set_content(message)
|
katzei_email.set_content(message)
|
||||||
email["From"] = sender
|
katzei_email["From"] = sender
|
||||||
email["To"] = config.get("email", "reciever")
|
katzei_email["To"] = config.get("email", "reciever")
|
||||||
|
katzei_email["Subject"] = config.get("email", "subject")
|
||||||
|
|
||||||
|
contact_email = EmailMessage()
|
||||||
|
contact_email.set_content(message)
|
||||||
|
contact_email["From"] = config.get("email", "sender")
|
||||||
|
contact_email["To"] = sender
|
||||||
|
contact_email["Subject"] = config.get("email", "subject")
|
||||||
|
|
||||||
smtp = SMTP(config.get("email", "server"))
|
smtp = SMTP(config.get("email", "server"))
|
||||||
smtp.send_message(email)
|
smtp.send_message(katzei_email)
|
||||||
|
smtp.send_message(contact_email)
|
||||||
smtp.quit()
|
smtp.quit()
|
||||||
|
|
||||||
|
|
||||||
@app.route(config.get("app", "path"), methods=["GET"])
|
@app.route(config.get("app", "path"), methods=["GET"])
|
||||||
def get_form(context=None):
|
def get_form(context=None):
|
||||||
context = (context or {}) | generate_captacha()
|
context = (context or {}) | generate_captacha()
|
||||||
@ -107,3 +119,5 @@ def validate_form():
|
|||||||
return get_form(context=context)
|
return get_form(context=context)
|
||||||
send_email(sender=form["email"], message=form["message"])
|
send_email(sender=form["email"], message=form["message"])
|
||||||
return flask.render_template("success.html")
|
return flask.render_template("success.html")
|
||||||
|
|
||||||
|
application=app
|
Loading…
Reference in New Issue
Block a user