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
from flask import Flask
#OIDC Login path
# OIDC Login path
from flask_oidc import OpenIDConnect
# Flask Login Path
# Flask Login Path
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
from core.utils import Logger
app = Flask(__name__)
app.config.from_object("core.config.Config")
@ -23,6 +27,7 @@ login_manager = LoginManager(app)
bcrypt = Bcrypt(app)
logger = Logger().get_logger()
def oidc_loggedin():
return oidc.user_loggedin
@ -33,15 +38,19 @@ def oidc_isAdmin():
return True
return False
app.jinja_env.globals['oidc_loggedin'] = oidc_loggedin
app.jinja_env.globals['oidc_isAdmin'] = oidc_isAdmin
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)
with app.app_context():
db.create_all()
from core.forms import RegisterForm, LoginForm
from core.forms import RegisterForm
from core.forms import LoginForm
from core import routes

View File

@ -1,14 +1,14 @@
{
"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",
"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]",
"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",
"token_uri": "http://localhost:8080/auth/realms/apps/protocol/openid-connect/token",
"token_introspection_uri": "http://localhost:8080/auth/realms/apps/protocol/openid-connect/token/introspect"
"userinfo_uri": "https://www.ssoapps.com/auth/realms/apps/protocol/openid-connect/userinfo",
"token_uri": "https://www.ssoapps.com/auth/realms/apps/protocol/openid-connect/token",
"token_introspection_uri": "https://www.ssoapps.com/auth/realms/apps/protocol/openid-connect/token/introspect"
}
}

View File

@ -1,14 +1,15 @@
# System import
import os, secrets, json
# Python imports
import os
import secrets
import json
from datetime import timedelta
# Lib imports
# Apoplication imports
APP_NAME = ':::APP TITLE:::'
ROOT_FILE_PTH = os.path.dirname(os.path.realpath(__file__))
# 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_TRACK_MODIFICATIONS = False
REGISTER_DISABLED = False
LOGIN_DISABLED = False
LOGIN_PATH = "FLASK_LOGIN" # Value can be OIDC or FLASK_LOGIN
OIDC_TOKEN_TYPE_HINT = 'access_token'
APP_REDIRECT_URI = REDIRECT_LINK

View File

@ -1,9 +1,23 @@
# Python imports
# Lib imports
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
class RegisterForm(FlaskForm):
username = StringField('Username', validators=[DataRequired(), Length(min=4, max=24)])
email = StringField('Email', validators=[DataRequired(), Email()])

View File

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

View File

@ -1,6 +1,10 @@
from . import Routes
from .pages import Flask_Login
from .pages import Flask_Register
from .pages import OIDC_Login
from .pages import OIDC_Register
from .pages import LoginManager
"""
Routes module
"""
from .login_controller import flask_login
from .login_controller import flask_register
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
# 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
ROUTE = app.config['LOGIN_PATH']

View File

@ -1,19 +1,32 @@
# Python imports
# Lib imports
from flask import request, render_template, flash, redirect, url_for
from flask_login import current_user, login_user, logout_user
from flask import flash
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
msgHandler = MessageHandler()
@app.route('/app-login', methods=['GET', 'POST'])
def app_login():
if current_user.is_authenticated:
if current_user.is_authenticated or app.config["LOGIN_DISABLED"]:
return redirect(url_for("home"))
_form = LoginForm()

View File

@ -1,20 +1,31 @@
# Python 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.utils import MessageHandler # Get simple message processor
msgHandler = MessageHandler()
@app.route('/app-register', methods=['GET', 'POST'])
def app_register():
if current_user.is_authenticated:
if current_user.is_authenticated or app.config["REGISTER_DISABLED"]:
return redirect(url_for("home"))
_form = RegisterForm()

View File

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

View File

@ -1,19 +1,28 @@
# Python 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
msgHandler = MessageHandler()
@app.route('/oidc-register', methods=['GET', 'POST'])
def oidc_register():
if oidc.user_loggedin:
if oidc.user_loggedin or app.config["REGISTER_DISABLED"]:
return redirect("/home")
_form = RegisterForm()

View File

@ -1,15 +1,21 @@
# Python imports
# Lib imports
from flask import request, render_template
from flask import request
from flask import render_template
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
msgHandler = MessageHandler()

View File

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

View File

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

View File

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

View File

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

View File

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