This repository was archived by the owner on Apr 21, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformidable.py
More file actions
40 lines (31 loc) · 1.45 KB
/
formidable.py
File metadata and controls
40 lines (31 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from flask import Flask, render_template, request, redirect
from flask_mail import Mail, Message
from os import environ
app = Flask(__name__)
app.config.from_object('config.local')
settings = environ.get('FORMIDABLE_SETTINGS_MODULE', None)
if settings:
app.config.from_object(settings)
if not app.config.get('SPAM_PAGE_DEFAULT'):
app.config['SPAM_PAGE_DEFAULT'] = app.config.get('THANKYOU_PAGE_DEFAULT')
mail = Mail(app)
@app.route("/submit", methods=['POST'])
def submit():
if app.config.get('GOTCHA_FIELD') and request.form.get(app.config.get('GOTCHA_FIELD')):
next_page = request.form.get('next_page', app.config.get('SPAM_PAGE_DEFAULT'))
return redirect(next_page)
referrer = request.referrer
originator = request.form.get('email', 'unknown')
mailtext = render_template('new_submit_mail.txt', form=request.form, referrer=request.referrer)
message = Message(body=mailtext,
subject='New form submission on {} from {}'.format(referrer, originator),
sender=app.config.get('MAIL_SENDER'),
recipients=app.config.get('MAIL_RECIPIENTS'),
reply_to=originator if originator != 'unknown' else None
)
if not app.config.get('DEBUG'):
mail.send(message)
next_page = request.form.get('next_page', app.config.get('THANKYOU_PAGE_DEFAULT'))
return redirect(next_page)
if __name__ == '__main__':
app.run()