Skip to content

Commit

Permalink
constants file created and more detailed debug messages added
Browse files Browse the repository at this point in the history
  • Loading branch information
DogukanUrker committed Jan 13, 2024
1 parent dbe060e commit f84e8c9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 20 deletions.
12 changes: 6 additions & 6 deletions UISelector.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
tailwindUI = False
from constants import TAILWIND_UI


match tailwindUI:
match TAILWIND_UI:
case True:
templateFolder = "templates/tailwindUI"
staticFolder = "static/tailwindUI"
TEMPLATE_FOLDER = "templates/tailwindUI"
STATIC_FOLDER = "static/tailwindUI"
case False:
templateFolder = "templates/standardUI"
staticFolder = "static/standardUI"
TEMPLATE_FOLDER = "templates/standardUI"
STATIC_FOLDER = "static/standardUI"
52 changes: 41 additions & 11 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import socket
from helpers import message

message("3", "APP IS STARTING...")


from helpers import (
secrets,
message,
render_template,
getProfilePicture,
Flask,
)


from routes.post import postBlueprint
from routes.user import userBlueprint
from routes.index import indexBlueprint
Expand All @@ -33,21 +35,47 @@


from flask_wtf.csrf import CSRFProtect, CSRFError
from UISelector import templateFolder, staticFolder
from dbChecker import dbFolder, usersTable, postsTable, commentsTable

from constants import (
APP_HOST,
DEBUG_MODE,
TAILWIND_UI,
REGISTRATION,
LOG_FILE_ROOT,
APP_SECRET_KEY,
SESSION_PERMANENT,
)
from UISelector import TEMPLATE_FOLDER, STATIC_FOLDER

app = Flask(__name__, template_folder=TEMPLATE_FOLDER, static_folder=STATIC_FOLDER)
app.secret_key = APP_SECRET_KEY
app.config["SESSION_PERMANENT"] = SESSION_PERMANENT
csrf = CSRFProtect(app)


message("1", f"APP DEBUG MODE: {DEBUG_MODE}")
message("3", f"APP HOST: {APP_HOST}")
message("3", f"APP SECRET KEY: {APP_SECRET_KEY}")
message("3", f"APP SESSION PERMANENT: {SESSION_PERMANENT}")
message("3", f"LOG FILE ROOT: {LOG_FILE_ROOT}")
message("3", f"REGISTRATION: {REGISTRATION}")

match TAILWIND_UI:
case True:
message("4", f"UI MODE: TAILWIND-CSS")
case False:
message("4", f"UI MODE: STANDARD-CSS")

message("4", f"TEMPLATE FOLDER: {TEMPLATE_FOLDER}")
message("4", f"STATIC FOLDER: {STATIC_FOLDER}")

dbFolder()
usersTable()
postsTable()
commentsTable()


app = Flask(__name__, template_folder=templateFolder, static_folder=staticFolder)
app.secret_key = secrets.token_urlsafe(32)
app.config["SESSION_PERMANENT"] = True
csrf = CSRFProtect(app)


@app.context_processor
def utility_processor():
getProfilePicture
Expand All @@ -61,6 +89,7 @@ def notFound(e):

@app.errorhandler(CSRFError)
def handle_csrf_error(e):
message("1", "CSRF ERROR")
return render_template("csrfError.html", reason=e.description), 400


Expand Down Expand Up @@ -89,4 +118,5 @@ def handle_csrf_error(e):

match __name__:
case "__main__":
app.run(debug=True, host=socket.gethostbyname(socket.gethostname()))
message("2", "APP STARTED SUCCESSFULLY")
app.run(debug=DEBUG_MODE, host=APP_HOST)
9 changes: 9 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from helpers import secrets, socket

APP_HOST = socket.gethostbyname(socket.gethostname())
DEBUG_MODE = True
TAILWIND_UI = False
REGISTRATION = True
LOG_FILE_ROOT = "log.log"
APP_SECRET_KEY = secrets.token_urlsafe(32)
SESSION_PERMANENT = True
4 changes: 3 additions & 1 deletion helpers.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import os
import ssl
import socket
import smtplib
import secrets
import sqlite3
from os import mkdir
from random import randint
from os.path import exists
from datetime import datetime
from constants import LOG_FILE_ROOT
from email.message import EmailMessage
from passlib.hash import sha256_crypt
from flask import render_template, Blueprint
Expand Down Expand Up @@ -51,7 +53,7 @@ def message(color, message):
f"\033[95m {currentTime(True)}]\033[0m"
f"\033[9{color}m {message}\033[0m\n"
)
logFile = open("log.log", "a", encoding="utf-8")
logFile = open(LOG_FILE_ROOT, "a", encoding="utf-8")
logFile.write(f"[{currentDate()}" f"|{currentTime(True)}]" f" {message}\n")
logFile.close()

Expand Down
3 changes: 1 addition & 2 deletions routes/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@
signUpForm,
sha256_crypt,
)
from constants import REGISTRATION

signUpBlueprint = Blueprint("signup", __name__)

REGISTRATION = True


@signUpBlueprint.route("/signup", methods=["GET", "POST"])
def signup():
Expand Down

0 comments on commit f84e8c9

Please sign in to comment.