Updating Bootstrap; refactoring dir structure, Pep 8 import cleanup

This commit is contained in:
itdominator 2023-03-11 21:10:29 -06:00
parent 333f4fe8c0
commit e09a702896
28 changed files with 153 additions and 71 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 412 KiB

After

Width:  |  Height:  |  Size: 416 KiB

View File

@ -4,17 +4,21 @@ import os
# Lib imports # Lib imports
from flask import Flask from flask import Flask
#OIDC Login path # OIDC Login path
from flask_oidc import OpenIDConnect from flask_oidc import OpenIDConnect
# Flask Login Path # Flask Login Path
from flask_bcrypt import Bcrypt from flask_bcrypt import Bcrypt
from flask_login import current_user, login_user, logout_user, LoginManager
from flask_login import current_user
from flask_login import login_user
from flask_login import logout_user
from flask_login import LoginManager
# Apoplication imports # Apoplication imports
from core.utils import Logger from core.utils import Logger
app = Flask(__name__) app = Flask(__name__)
app.config.from_object("core.config.Config") app.config.from_object("core.config.Config")
@ -23,6 +27,7 @@ login_manager = LoginManager(app)
bcrypt = Bcrypt(app) bcrypt = Bcrypt(app)
logger = Logger().get_logger() logger = Logger().get_logger()
def oidc_loggedin(): def oidc_loggedin():
return oidc.user_loggedin return oidc.user_loggedin
@ -33,15 +38,19 @@ def oidc_isAdmin():
return True return True
return False return False
app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin
app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin
app.jinja_env.globals['TITLE'] = app.config["TITLE"] app.jinja_env.globals['TITLE'] = app.config["TITLE"]
from core.models import db, User from core.models import db
from core.models import User
db.init_app(app) db.init_app(app)
with app.app_context(): with app.app_context():
db.create_all() db.create_all()
from core.forms import RegisterForm, LoginForm from core.forms import RegisterForm
from core.forms import LoginForm
from core import routes from core import routes

View File

@ -1,14 +1,14 @@
{ {
"web": { "web": {
"auth_uri": "http://localhost:8080/auth/realms/apps/protocol/openid-connect/auth", "auth_uri": "https://www.ssoapps.com/auth/realms/apps/protocol/openid-connect/auth",
"client_id": "apps", "client_id": "apps",
"issuer": "http://localhost:8080/auth/realms/apps", "issuer": "https://www.ssoapps.com/auth/realms/apps",
"client_secret": "[ADD YOUR SECRET FROM THE REALM>CLIENTS>apps>Credentials Tab]", "client_secret": "[ADD YOUR SECRET FROM THE REALM>CLIENTS>apps>Credentials Tab]",
"redirect_uris": [ "redirect_uris": [
"http://localhost:6969/" "https%3A%2F%2Fwww.your-domain-here.com%2F"
], ],
"userinfo_uri": "http://localhost:8080/auth/realms/apps/protocol/openid-connect/userinfo", "userinfo_uri": "https://www.ssoapps.com/auth/realms/apps/protocol/openid-connect/userinfo",
"token_uri": "http://localhost:8080/auth/realms/apps/protocol/openid-connect/token", "token_uri": "https://www.ssoapps.com/auth/realms/apps/protocol/openid-connect/token",
"token_introspection_uri": "http://localhost:8080/auth/realms/apps/protocol/openid-connect/token/introspect" "token_introspection_uri": "https://www.ssoapps.com/auth/realms/apps/protocol/openid-connect/token/introspect"
} }
} }

View File

@ -1,14 +1,15 @@
# System import # Python imports
import os, secrets, json import os
import secrets
import json
from datetime import timedelta from datetime import timedelta
# Lib imports # Lib imports
# Apoplication imports # Apoplication imports
APP_NAME = ':::APP TITLE:::' APP_NAME = ':::APP TITLE:::'
ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__)) ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__))
# This path is submitted as the redirect URI in certain code flows. # This path is submitted as the redirect URI in certain code flows.
@ -35,6 +36,8 @@ class Config(object):
SQLALCHEMY_DATABASE_URI = "sqlite:///static/db/database.db" SQLALCHEMY_DATABASE_URI = "sqlite:///static/db/database.db"
SQLALCHEMY_TRACK_MODIFICATIONS = False SQLALCHEMY_TRACK_MODIFICATIONS = False
REGISTER_DISABLED = False
LOGIN_DISABLED = False
LOGIN_PATH = "FLASK_LOGIN" # Value can be OIDC or FLASK_LOGIN LOGIN_PATH = "FLASK_LOGIN" # Value can be OIDC or FLASK_LOGIN
OIDC_TOKEN_TYPE_HINT = 'access_token' OIDC_TOKEN_TYPE_HINT = 'access_token'
APP_REDIRECT_URI = REDIRECT_LINK APP_REDIRECT_URI = REDIRECT_LINK

View File

@ -1,9 +1,23 @@
# Python imports
# Lib imports
from flask_wtf import FlaskForm from flask_wtf import FlaskForm
from wtforms import StringField, PasswordField, SubmitField
from wtforms.validators import DataRequired, Length, Email, EqualTo, ValidationError from wtforms import StringField
from wtforms import PasswordField
from wtforms import SubmitField
from wtforms.validators import DataRequired
from wtforms.validators import Length
from wtforms.validators import Email
from wtforms.validators import EqualTo
from wtforms.validators import ValidationError
# Apoplication imports
from core import User from core import User
class RegisterForm(FlaskForm): class RegisterForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=4, max=24)]) username = StringField('Username', validators=[DataRequired(), Length(min=4, max=24)])
email = StringField('Email', validators=[DataRequired(), Email()]) email = StringField('Email', validators=[DataRequired(), Email()])

View File

@ -1,7 +1,12 @@
# Python imports
from flask_sqlalchemy import SQLAlchemy # Lib imports
from core import app, login_manager
from flask_login import UserMixin from flask_login import UserMixin
from flask_sqlalchemy import SQLAlchemy
# Apoplication imports
from core import app, login_manager
db = SQLAlchemy(app) db = SQLAlchemy(app)

View File

@ -1,6 +1,10 @@
from . import Routes """
from .pages import Flask_Login Routes module
from .pages import Flask_Register """
from .pages import OIDC_Login from .login_controller import flask_login
from .pages import OIDC_Register from .login_controller import flask_register
from .pages import LoginManager from .login_controller import oidc_login
from .login_controller import oidc_register
from .login_controller import controller
from . import routes

View File

@ -0,0 +1,3 @@
"""
Login module
"""

View File

@ -1,12 +1,15 @@
# Python imports # Python imports
# Lib imports # Lib imports
from flask import redirect, url_for, flash from flask import redirect
from flask import url_for
from flask import flash
# App imports # Application imports
from core import app from core import app
ROUTE = app.config['LOGIN_PATH'] ROUTE = app.config['LOGIN_PATH']

View File

@ -1,19 +1,32 @@
# Python imports # Python imports
# Lib imports # Lib imports
from flask import request, render_template, flash, redirect, url_for from flask import flash
from flask_login import current_user, login_user, logout_user from flask import redirect
from flask import request
from flask import render_template
from flask import url_for
from flask_login import current_user
from flask_login import login_user
from flask_login import logout_user
# Application imports
from core import app
from core import bcrypt
from core import db
from core import User
from core import LoginForm
# App imports
from core import app, bcrypt, db, User, LoginForm
from core.utils import MessageHandler # Get simple message processor from core.utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler() msgHandler = MessageHandler()
@app.route('/app-login', methods=['GET', 'POST']) @app.route('/app-login', methods=['GET', 'POST'])
def app_login(): def app_login():
if current_user.is_authenticated: if current_user.is_authenticated or app.config["LOGIN_DISABLED"]:
return redirect(url_for("home")) return redirect(url_for("home"))
_form = LoginForm() _form = LoginForm()

View File

@ -1,20 +1,31 @@
# Python imports # Python imports
# Lib imports # Lib imports
from flask import request, render_template, url_for, redirect, flash from flask import flash
from flask import redirect
from flask import request
from flask import render_template
from flask import url_for
# Application imports
# Get from __init__
from core import app
from core import bcrypt
from core import db
from core import current_user
from core import RegisterForm
# App imports
from core import app, bcrypt, db, current_user, RegisterForm # Get from __init__
from core.models import User from core.models import User
from core.utils import MessageHandler # Get simple message processor from core.utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler() msgHandler = MessageHandler()
@app.route('/app-register', methods=['GET', 'POST']) @app.route('/app-register', methods=['GET', 'POST'])
def app_register(): def app_register():
if current_user.is_authenticated: if current_user.is_authenticated or app.config["REGISTER_DISABLED"]:
return redirect(url_for("home")) return redirect(url_for("home"))
_form = RegisterForm() _form = RegisterForm()

View File

@ -1,13 +1,15 @@
# Python imports # Python imports
# Lib imports # Lib imports
from flask import request, redirect, flash from flask import request
from flask import redirect
from flask import flash
# Application imports
# App imports
from ... import app, oidc from ... import app, oidc
@app.route('/oidc-login', methods=['GET', 'POST']) @app.route('/oidc-login', methods=['GET', 'POST'])
@oidc.require_login @oidc.require_login
def oidc_login(): def oidc_login():

View File

@ -1,19 +1,28 @@
# Python imports # Python imports
# Lib imports # Lib imports
from flask import request, render_template, url_for, redirect, flash from flask import flash
from flask import redirect
from flask import request
from flask import render_template
from flask import url_for
# Application imports
# Get from __init__
from ... import app
from ... import oidc
from ... import db
# App imports
from ... import app, oidc, db # Get from __init__
from ...utils import MessageHandler # Get simple message processor from ...utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler() msgHandler = MessageHandler()
@app.route('/oidc-register', methods=['GET', 'POST']) @app.route('/oidc-register', methods=['GET', 'POST'])
def oidc_register(): def oidc_register():
if oidc.user_loggedin: if oidc.user_loggedin or app.config["REGISTER_DISABLED"]:
return redirect("/home") return redirect("/home")
_form = RegisterForm() _form = RegisterForm()

View File

@ -1,15 +1,21 @@
# Python imports # Python imports
# Lib imports # Lib imports
from flask import request, render_template from flask import request
from flask import render_template
from flask_login import current_user from flask_login import current_user
# Application imports
# Get from __init__
from core import app
from core import logger
from core import oidc
from core import db
# App imports
from core import app, logger, oidc, db # Get from __init__
from core.utils import MessageHandler # Get simple message processor from core.utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler() msgHandler = MessageHandler()

View File

@ -25,12 +25,8 @@
{% block header_css %} {% block header_css %}
<!-- Bootstrap CSS --> <!-- Bootstrap CSS -->
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.png') }}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/libs/bootstrap5/bootstrap.min.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/libs/bootstrap-icons/bootstrap-icons.css')}}">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap5/bootstrap.min.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap5/bootstrap-dark.min.css')}}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/bootstrap-icons/bootstrap-icons.css')}}">
<!-- Site CSS --> <!-- Site CSS -->
<link rel="stylesheet" href="{{ url_for('static', filename='css/main.css')}}"> <link rel="stylesheet" href="{{ url_for('static', filename='css/main.css')}}">
@ -47,21 +43,21 @@
{% endblock %} {% endblock %}
</head> </head>
{% endblock %} {% endblock %}
<body> <body data-bs-theme="dark">
<video id="bg" src="{{ url_for('static', filename='imgs/backgrounds/particles.mp4')}}" <video id="bg" src="{{ url_for('static', filename='imgs/backgrounds/particles.mp4')}}"
poster="{{ url_for('static', filename='imgs/backgrounds/background.png')}}" poster="{{ url_for('static', filename='imgs/backgrounds/background.png')}}"
autoplay loop> autoplay loop>
</video> </video>
<div class="menu"> <div class="menu">
<ul class="menu-options"> <ul class="menu-options">
<li class="menu-option">Back</li> <li class="menu-option">Back</li>
<li class="menu-option">Reload</li> <li class="menu-option">Reload</li>
<li class="menu-option">Save</li> <li class="menu-option">Save</li>
<li class="menu-option">Save As</li> <li class="menu-option">Save As</li>
<li class="menu-option">Delete</li> <li class="menu-option">Delete</li>
<li class="menu-option">Spy</li> <li class="menu-option">Spy</li>
</ul> </ul>
</div> </div>
{% block body_header %} {% block body_header %}
@ -111,9 +107,9 @@
<script src="{{ url_for('static', filename='js/libs/bootstrap5/bootstrap.bundle.min.js')}}"></script> <script src="{{ url_for('static', filename='js/libs/bootstrap5/bootstrap.bundle.min.js')}}"></script>
<!-- For React --> <!-- For React -->
<script src="{{ url_for('static', filename='js/libs/babel.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/libs/react/react.production.min.js')}}"></script> <script src="{{ url_for('static', filename='js/libs/react/react.production.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/libs/react/react-dom.production.min.js')}}"></script> <script src="{{ url_for('static', filename='js/libs/react/react-dom.production.min.js')}}"></script>
<script src="{{ url_for('static', filename='js/libs/babel.min.js')}}"></script>
<!-- Application Imports --> <!-- Application Imports -->
{% block body_scripts_additional %} {% block body_scripts_additional %}

View File

@ -16,8 +16,7 @@
{% block body_content_additional %} {% block body_content_additional %}
<div class="row"> <div class="row">
<div class="col justify-content-center text-center"> <div class="col justify-content-center text-center">
<p>Using Bootstrap 5 Themeing...</p> <p>Using Bootstrap 5 Themeing with Dark Mode defaulted...</p>
<p>Themes:&nbsp;<a href="https://bootswatch.com/" target="_blank">Bootswatch</a></p>
<p>With React available...</p> <p>With React available...</p>
<p>A React Example Page:&nbsp; <p>A React Example Page:&nbsp;
<a href="{{ url_for('react_page') }}"> <a href="{{ url_for('react_page') }}">

View File

@ -1,7 +1,11 @@
# Python imports # Python imports
import os, logging import os
import logging
# Lib imports
# Apoplication imports
# Application imports
class Logger: class Logger:

View File

@ -1,8 +1,9 @@
# Gtk imports
# Python imports # Python imports
# Application imports # Lib imports
# Apoplication imports
class MessageHandler: class MessageHandler:

View File

@ -8,7 +8,7 @@
function main() { function main() {
SCRIPTPATH="$( cd "$(dirname "")" >/dev/null 2>&1 ; pwd -P )" SCRIPTPATH="$( cd "$(dirname "")" >/dev/null 2>&1 ; pwd -P )"
echo "Working Dir: " $(pwd) echo "Working Dir: " $(pwd)
source "../venv/bin/activate" # source "../venv/bin/activate"
LOG_LEVEL=debug LOG_LEVEL=debug
WORKER_COUNT=1 WORKER_COUNT=1
@ -20,7 +20,7 @@ function main() {
# Note: NEED -k eventlet for this to work! I spent too many hours on this... # Note: NEED -k eventlet for this to work! I spent too many hours on this...
# <module>:<app> IE <file>:<flask app variable> # <module>:<app> IE <file>:<flask app variable>
gunicorn wsgi:app -p app.pid -b $ADDR:$PORT \ gunicorn wsgi:app -p app.pid -b $ADDR:$PORT \
-k eventlet \ # -k eventlet \
-w $WORKER_COUNT \ -w $WORKER_COUNT \
--timeout $TIMEOUT \ --timeout $TIMEOUT \
--log-level $LOG_LEVEL --log-level $LOG_LEVEL