-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
44 lines (31 loc) · 1 KB
/
app.py
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
41
42
43
import uuid
import logging
from flask import Flask, request, render_template
from flask_session import Session
from flask_session_captcha import FlaskSessionCaptcha
from pymongo import MongoClient
app = Flask(__name__)
mongoClient = MongoClient('localhost', 27017)
#captcha config
app.config["SECRET_KEY"] = uuid.uuid4()
app.config['CAPTCHA_ENABLE'] = True
app.config['CAPTCHA_LENGTH'] = 5
app.config['CAPTCHA_WIDTH'] = 160
app.config['CAPTCHA_HEIGHT'] = 60
app.config['SESSION_MONGODB'] = mongoClient
app.config['SESSION_TYPE'] = 'mongodb'
app.config['SESSION_COOKIE_NAME'] = 'your_session_cookie_name'
Session(app) #enable server session
captcha = FlaskSessionCaptcha(app)
@app.route('/', methods = ['POST', 'GET'])
def index():
if request.method == "POST":
if captcha.validate():
return "success"
else:
return "fail"
return render_template('form.html')
if __name__ == "__main__":
app.run(debug=True)
logging.getLogger().setLevel("DEBUG")
app.run()