diff --git a/README.md b/README.md index 8a58d10..0b54710 100644 --- a/README.md +++ b/README.md @@ -5,25 +5,9 @@ A template to quickly standup a flask webapp with bootstrap and a database. ``` sudo apt install python3 ``` # Setup -*** Change directory to Flask-Project-Template/ or rename the folder before doing so. - -``` python3 -m venv venv/ ``` - -Linux/Mac -``` source bin/activate ``` - -Windows -``` source bin/Scripts/activate ``` - -Linux/Mac -``` pip install -r linux-requirements.txt ``` - -Windows -``` pip install -r windows-requirements.txt ``` - - -``` cd src/ ``` +*** Change directory to Flask-Project-Template/ or rename the folder before doing so. Then either run the create_venv.sh script. For windows, you'll need git bash. You can also just create the venv yourself and pip install the dependencies thereafter. +*** To start the application: Linux/Mac ``` ./linux-start.sh ``` @@ -33,4 +17,8 @@ Windows # Notes -Make sure to change the port in the start script as needed. Have fun! +* Make sure to change the port in the start script as needed. +* You can change the login route by changing the 'LOGIN_PATH' variable in the __init__.py file in the 'core' directory. +* Get [Keycloak](https://www.keycloak.org) to use oidc login route. +* If using Keycloak, make sure to change the client_secrets.json file values to match your Keycloak settings. Or, match Keycloak settings to the client_secrets.json file. +* Have fun! diff --git a/src/core/__init__.py b/src/core/__init__.py index dd2fcef..3c5e12b 100644 --- a/src/core/__init__.py +++ b/src/core/__init__.py @@ -48,10 +48,15 @@ login_manager = LoginManager(app) bcrypt = Bcrypt(app) +def oidc_loggedin(): + return oidc.user_loggedin +app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin +app.jinja_env.globals['TITLE'] = ':::APP TITLE:::' + + from core.models import db, User with app.app_context(): db.create_all() - from core.forms import RegisterForm, LoginForm from core import routes diff --git a/src/core/routes/Routes.py b/src/core/routes/Routes.py index dc19763..0a2991f 100644 --- a/src/core/routes/Routes.py +++ b/src/core/routes/Routes.py @@ -2,21 +2,21 @@ # Lib imports from flask import request, render_template +from flask_login import current_user + # App imports -from core import app, db # Get from __init__ +from core import app, oidc, db # Get from __init__ from core.utils import MessageHandler # Get simple message processor msgHandler = MessageHandler() -TITLE = app.config['TITLE'] @app.route('/', methods=['GET', 'POST']) def home(): if request.method == 'GET': - return render_template('index.html', - title=TITLE) + return render_template('index.html') return render_template('error.html', title='Error!', @@ -26,9 +26,20 @@ def home(): @app.route('/about', methods=['GET', 'POST']) def about(): if request.method == 'GET': - return render_template('about.html', - title=TITLE) + return render_template('about.html') - return render_template('error.html', - title='Error!', - message='Must use GET request type...') + return render_template('error.html', title = 'Error!', + message = 'Must use GET request type...') + + +@app.route('/protected-zone', methods=['GET', 'POST']) +def protected_zone(): + if request.method == 'GET': + msg = "Log in to see the secret!" + if current_user.is_authenticated or oidc.user_loggedin: + msg = "There is no secret! It was all a lie!" + + return render_template('protected.html', secret = msg) + + return render_template('error.html', title = 'Error!', + message = 'Must use GET request type...') diff --git a/src/core/templates/body-header.html b/src/core/templates/body-header.html index db1ea69..41bd938 100644 --- a/src/core/templates/body-header.html +++ b/src/core/templates/body-header.html @@ -4,7 +4,7 @@