Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes #37

Merged
merged 8 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,37 @@
from dbChecker import dbFolder, usersTable, postsTable, commentsTable

from constants import (
LOG_IN,
APP_HOST,
APP_NAME,
DEBUG_MODE,
TAILWIND_UI,
LOG_IN,
REGISTRATION,
LOG_FILE_ROOT,
APP_ROOT_PATH,
APP_SECRET_KEY,
SESSION_PERMANENT,
)

from UISelector import TEMPLATE_FOLDER, STATIC_FOLDER

app = Flask(__name__, template_folder=TEMPLATE_FOLDER, static_folder=STATIC_FOLDER)
app = Flask(
import_name=APP_NAME,
root_path=APP_ROOT_PATH,
static_folder=STATIC_FOLDER,
template_folder=TEMPLATE_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 NAME: {APP_NAME}")
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"APP ROOT PATH: {APP_ROOT_PATH}")
message("3", f"LOG FILE ROOT: {LOG_FILE_ROOT}")
message("3", f"LOG IN: {LOG_IN}")
message("3", f"REGISTRATION: {REGISTRATION}")
Expand Down Expand Up @@ -119,8 +129,14 @@
app.register_blueprint(adminPanelCommentsBlueprint)
app.register_blueprint(changeProfilePictureBlueprint)

message("2", "APP STARTED SUCCESSFULLY")

match __name__:
case "__main__":
app.run(debug=DEBUG_MODE, host=APP_HOST)
try:
message("2", "APP STARTED SUCCESSFULLY")
app.run(debug=DEBUG_MODE, host=APP_HOST)
Dismissed Show dismissed Hide dismissed
except:
message("1", "ERROR: APP IS DOWN")
app.run(debug=DEBUG_MODE, host=APP_HOST)
Dismissed Show dismissed Hide dismissed
finally:
message("3", "APP SHUT DOWN")
2 changes: 2 additions & 0 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from helpers import secrets, socket

APP_NAME = "flaskBlog" # NAME OF THE FLASK APP.
APP_ROOT_PATH = "." # THE PATH TO THE ROOT OF THE APP FILES.
APP_HOST = socket.gethostbyname(socket.gethostname()) # FLASK APP'S HOST/PORT.
DEBUG_MODE = True # TURN ON/OFF FLASK DEBUG MODE.
TAILWIND_UI = False # SELECT TAILWIND-UI/STANDARD-UI.
Expand Down
2 changes: 1 addition & 1 deletion forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from wtforms import validators, Form, StringField, PasswordField, TextAreaField

inputStyle = "w-80 h-12 mb-4 mx-auto p-2 rounded-md text-center outline-rose-500 bg-transparent focus:outline-none focus:ring focus:ring-rose-500 duration-100 border-2 border-gray-500/25 focus:border-0 block shadow-md"
inputStyle = "w-80 h-12 mb-4 mx-auto p-2 rounded-md text-center outline-rose-500 bg-transparent focus:outline-none focus:ring focus:ring-rose-500 duration-100 border-2 border-gray-500/25 focus:border-0 block shadow-md select-none"


class commentForm(Form):
Expand Down
92 changes: 55 additions & 37 deletions templates/tailwindUI/adminPanelUsers.html
Original file line number Diff line number Diff line change
@@ -1,66 +1,84 @@
{% extends 'layout.html'%} {%block head%}
<title>Admin Panel</title>
{% endblock head %} {%block body%}
<div>
<h1>Users</h1>
<div class="text-center">
<h1 class="my-4 text-4xl font-medium select-none">Users</h1>
{% for user in users %}
<div>
<section>
<p>ID: {{user[0]}}</p>
<p>Role: {{user[5]}}</p>
<div
class="w-12/12 md:w-8/12 lg:w-2/4 xl:w-4/12 h-fit mx-px md:mx-auto py-2 px-2 my-4 border-2 rounded-md shadow-md
border-gray-500/25"
>
<section class="mb-4 text-center">
<img
src="{{user[4]}}"
alt="{{user[1]}}"
class="w-20 m-2 mx-auto select-none"
/>
<p class="self-end">
<a
href="/user/{{user[1].lower()}}"
class="hover:text-rose-500 duration-150"
>{{user[1]}}</a
>
</p>
</section>
<section>
<p>
User Name:
<a href="/user/{{user[1].lower()}}">{{user[1]}}</a>
<section class="flex w-full justify-between my-4">
<p class="flex items-center">
<i class="ti ti-id mr-1 text-xl"></i>ID: {{user[0]}}
</p>
<p class="flex items-center">
<i class="ti ti-user mr-1 text-xl"></i>Role: {{user[5]}}
</p>
<img src="{{user[4]}}" alt="{{user[1]}}" />
</section>
<section>
<p>email: {{user[2]}}</p>
<p>Points: {{user[6]}}</p>
<section class="flex w-full justify-between my-4">
<p class="flex items-centers text-left">
<i class="ti ti-mail mr-1 text-xl"></i>email: {{user[2]}}
</p>
<p class="flex items-center">
<i class="ti ti-sparkles mr-1 text-xl"></i>Points: {{user[6]}}
</p>
</section>
<section>
<p>Join Date: {{user[7]}}</p>
<p>Join Time: {{user[8]}}</p>
<section class="flex w-full justify-between my-4">
<p class="flex items-center">
<i class="ti ti-calendar mr-1 text-xl"></i>Join Date: {{user[7]}}
</p>
<p class="flex items-center">
<i class="ti ti-clock mr-1 text-xl"></i>Join Time: {{user[8]}}
</p>
</section>
<section>
<section class="flex w-full justify-between mt-4">
<form method="post">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}" />
<input type="hidden" name="userName" value="{{user[1]}}" />
<button
type="submit"
name="userDeleteButton"
class="block mx-auto m-2 hover:text-rose-500 duration-150 font-medium"
class="flex items-center hover:text-rose-500 duration-150 font-medium select-none"
>
<i class="ti ti-trash mr-1 text-xl"></i>
delete user
</button>
</form>
{% if user[5] == "admin" %}
<a href="/setuserrole/{{user[1].lower()}}/user">set user role to user</a>
<a
href="/setuserrole/{{user[1].lower()}}/user"
class="flex items-center hover:text-rose-500 duration-150 font-medium select-none"
><i class="ti ti-user-down mr-1 text-xl"></i> set user role to user</a
>
{% else %}
<a href="/setuserrole/{{user[1].lower()}}/admin"
>set user role to admin</a
<a
href="/setuserrole/{{user[1].lower()}}/admin"
class="flex items-center hover:text-rose-500 duration-150 font-medium select-none"
><i class="ti ti-user-up mr-1 text-xl"></i>set user role to admin</a
>
{% endif %}
</section>
</div>
{% endfor %}
</div>
<a href="/admin"
><svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke-width="1.5"
stroke="currentColor"
class="w-6 h-6 hover:text-rose-500 duration-150"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
d="M9 15 3 9m0 0 6-6M3 9h12a6 6 0 0 1 0 12h-3"
/>
</svg>
<a href="/admin" class="fixed bottom-0 left-1"
><i
class="ti ti-arrow-back mr-1 text-xl hover:text-rose-500 duration-150"
></i>
</a>
{% endblock body %}
2 changes: 1 addition & 1 deletion templates/tailwindUI/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<title>flaskBlog</title>
{% endblock head %} {%block body%} {% for post in posts %}
<div
class="w-11/12 md:w-10/12 lg:w-3/4 xl:w-1/2 h-96 mx-auto py-4 px-2 my-16 border-2 rounded-md shadow-md
class="w-11/12 md:w-10/12 lg:w-3/4 xl:w-1/2 h-96 mx-auto py-4 px-2 my-8 border-2 rounded-md shadow-md
border-gray-500/25"
>
<a
Expand Down
4 changes: 2 additions & 2 deletions templates/tailwindUI/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
border-gray-500/25 focus:border-rose-500 block shadow-md")}}
<button
type="submit"
class="block mx-auto m-2 hover:text-rose-500 duration-150 font-medium"
class="block mx-auto m-2 hover:text-rose-500 duration-150 font-medium select-none"
>
Login
</button>
<a
href="/passwordreset/codesent=false"
id="passwordReset"
class="hover:text-rose-500 duration-150 text-sm font-normal"
class="hover:text-rose-500 duration-150 text-sm font-normal select-none"
>Forgot password?</a
>
</form>
Expand Down
6 changes: 3 additions & 3 deletions templates/tailwindUI/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,18 @@
<i class="ti ti-user-plus text-2xl"></i>
</a>
{% elif hideSignUp %}
<a href="/login/redirect=&" class="w-7 h-7"
<a href="/login/redirect=&"
><button class="hover:text-rose-500 duration-150">
<i class="ti ti-login text-2xl"></i>
</button
></a>
{%else%}
<a href="/login/redirect=&" class="w-7 h-7"
<a href="/login/redirect=&"
><button class="hover:text-rose-500 duration-150">
<i class="ti ti-login text-2xl"></i>
</button
></a>
<a href="/signup" class="w-7 h-7"
<a href="/signup"
><button class="hover:text-rose-500 duration-150">
<i class="ti ti-user-plus text-2xl"></i>
</button
Expand Down
2 changes: 1 addition & 1 deletion templates/tailwindUI/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
{{form.password()}} {{form.passwordConfirm()}}
<button
type="submit"
class="block mx-auto m-2 hover:text-rose-500 duration-150 font-medium"
class="block mx-auto m-2 hover:text-rose-500 duration-150 font-medium select-none"
>
Signup
</button>
Expand Down