Improvements in logic.
This commit is contained in:
parent
7106d1cf18
commit
a64ad67115
26
README.md
26
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!
|
||||
|
@ -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
|
||||
|
@ -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...')
|
||||
|
@ -4,7 +4,7 @@
|
||||
<div class="navbar-brand justify-content-center text-center">
|
||||
<div class="site-branding">
|
||||
<h1 class="site-title">
|
||||
<a href="{{ url_for('home') }}" title="TITLE" rel="home">
|
||||
<a href="{{ url_for('home') }}" title="{{TITLE}} Home" rel="home">
|
||||
Hello World!
|
||||
</a>
|
||||
</h1>
|
||||
@ -84,7 +84,7 @@
|
||||
<i class="far fa-address-card"></i> About</a>
|
||||
</li>
|
||||
|
||||
{% if current_user.is_authenticated %}
|
||||
{% if current_user.is_authenticated or oidc_loggedin() %}
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{ url_for('logout') }}">
|
||||
<i class="fas fa-sign-out-alt"></i> Logout</a>
|
||||
|
@ -5,7 +5,7 @@
|
||||
{% if title %}
|
||||
<title>{{title}}</title>
|
||||
{% else %}
|
||||
<title>App</title>
|
||||
<title>{{TITLE}}</title>
|
||||
{% endif %}
|
||||
|
||||
{% block header_css %}
|
||||
|
25
src/core/templates/protected.html
Normal file
25
src/core/templates/protected.html
Normal file
@ -0,0 +1,25 @@
|
||||
{% extends "layout.html" %}
|
||||
|
||||
{% block body_header_additional %}
|
||||
{% endblock body_header_additional %}
|
||||
|
||||
{% block body_content %}
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col justify-content-center text-center">
|
||||
<h1>{{secret}}</h1>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock body_content %}
|
||||
|
||||
|
||||
{% block body_footer_additional %}
|
||||
{% endblock body_footer_additional %}
|
||||
|
||||
{% block body_scripts_additional %}
|
||||
<script src="{{ url_for('static', filename='js/ui-logic.js')}}"></script>
|
||||
<script src="{{ url_for('static', filename='js/post-ajax.js')}}"></script>
|
||||
<script src="{{ url_for('static', filename='js/ajax.js')}}"></script>
|
||||
<script src="{{ url_for('static', filename='js/events.js')}}"></script>
|
||||
{% endblock body_scripts_additional %}
|
Loading…
Reference in New Issue
Block a user