diff --git a/app/app.py b/app/app.py index 72e04d2..86287e6 100644 --- a/app/app.py +++ b/app/app.py @@ -3,10 +3,12 @@ """Flask web server.""" from flask import Flask, render_template, request +from flask_wtf.csrf import CSRFProtect from app.send_page import send_page app = Flask(__name__) +csrf = CSRFProtect(app) @app.route("/", methods=['GET']) def index(): diff --git a/app/main.py b/app/main.py index 4c32c13..9d17ff9 100644 --- a/app/main.py +++ b/app/main.py @@ -2,11 +2,15 @@ """Main module.""" -from app.app import app +import os + +from app.app import app, csrf def main(): """Run the app.""" + app.secret_key = os.urandom(12).hex() + csrf.init_app(app) app.run() diff --git a/app/templates/index.html b/app/templates/index.html index 90057e6..51ec836 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -24,7 +24,7 @@
- + ePage logo ePage
@@ -63,6 +63,7 @@

+ diff --git a/requirements.txt b/requirements.txt index f84c801..156722e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ certifi==2022.6.15 charset-normalizer==2.1.0 click==8.1.3 Flask==2.1.2 +flask_wtf-1.0.1 idna==3.3 itsdangerous==2.1.2 Jinja2==3.1.2 @@ -9,3 +10,4 @@ MarkupSafe==2.1.1 requests==2.28.1 urllib3==1.26.10 Werkzeug==2.1.2 +WTForms-3.0.1 \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py index 51da9b8..8e28d82 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,13 +2,16 @@ """PyTest unit tests.""" +import os import pytest -from app.app import app +from app.app import app, csrf @pytest.fixture def client(): """Set up Flask client for use in tests.""" + app.secret_key = os.urandom(12).hex() + csrf.init_app(app) client = app.test_client() yield client