Skip to content

Commit

Permalink
Merge pull request #36 from DogukanUrker/main
Browse files Browse the repository at this point in the history
changes
  • Loading branch information
DogukanUrker authored Jan 15, 2024
2 parents 6239ec6 + 0a07b9b commit 967abe1
Show file tree
Hide file tree
Showing 38 changed files with 203 additions and 515 deletions.
22 changes: 11 additions & 11 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from helpers import secrets, socket

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
LOG_IN = True # TURN ON/OFF USER LOG IN UP
REGISTRATION = True # TURN ON/OFF USER SIGN UP
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.
LOG_IN = True # TURN ON/OFF USER LOG IN UP.
REGISTRATION = True # TURN ON/OFF USER SIGN UP.
LOG_FILE_ROOT = "log.log" # ROOT OF THE LOG FILE FROM WHERE MESSAGES ARE PRINTED FROM THE MESSAGE MODULE.
DB_FOLDER_ROOT = "db" # ROOT OF THE DATABASE FOLDER WHERE .db FILES ARE LOCATED
DB_USERS_ROOT = DB_FOLDER_ROOT + "/users.db" # ROOT OF THE USERS DATABASE
DB_POSTS_ROOT = DB_FOLDER_ROOT + "/posts.db" # ROOT OF THE POSTS DATABASE
DB_COMMENTS_ROOT = DB_FOLDER_ROOT + "/comments.db" # ROOT OF THE COMMENTS DATABASE
APP_SECRET_KEY = secrets.token_urlsafe(32) # FLASK APP'S SECRET KEY
SESSION_PERMANENT = True # FLASK APP'S SESSIONS
DB_FOLDER_ROOT = "db" # ROOT OF THE DATABASE FOLDER WHERE .db FILES ARE LOCATED.
DB_USERS_ROOT = DB_FOLDER_ROOT + "/users.db" # ROOT OF THE USERS DATABASE.
DB_POSTS_ROOT = DB_FOLDER_ROOT + "/posts.db" # ROOT OF THE POSTS DATABASE.
DB_COMMENTS_ROOT = DB_FOLDER_ROOT + "/comments.db" # ROOT OF THE COMMENTS DATABASE.
APP_SECRET_KEY = secrets.token_urlsafe(32) # FLASK APP'S SECRET KEY.
SESSION_PERMANENT = True # FLASK APP'S SESSIONS.
18 changes: 13 additions & 5 deletions delete.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
from helpers import sqlite3, message, redirect, session
from helpers import (
sqlite3,
message,
session,
redirect,
DB_POSTS_ROOT,
DB_USERS_ROOT,
DB_COMMENTS_ROOT,
)


def deletePost(postID):
connection = sqlite3.connect("db/posts.db")
connection = sqlite3.connect(DB_POSTS_ROOT)
cursor = connection.cursor()
cursor.execute(f"select author from posts where id = {postID}")
cursor.execute(f"delete from posts where id = {postID}")
cursor.execute(f"update sqlite_sequence set seq = seq-1")
connection.commit()
connection.close()
connection = sqlite3.connect("db/comments.db")
connection = sqlite3.connect(DB_COMMENTS_ROOT)
cursor = connection.cursor()
cursor.execute(f"select count(*) from comments where post = {postID}")
commentCount = list(cursor)[0][0]
Expand All @@ -20,7 +28,7 @@ def deletePost(postID):


def deleteUser(userName):
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(f'select * from users where lower(userName) = "{userName.lower()}"')
cursor.execute(f'select role from users where userName = "{session["userName"]}"')
Expand All @@ -38,7 +46,7 @@ def deleteUser(userName):


def deleteComment(commentID):
connection = sqlite3.connect("db/comments.db")
connection = sqlite3.connect(DB_COMMENTS_ROOT)
cursor = connection.cursor()
cursor.execute(f"select user from comments where id = {commentID}")
cursor.execute(f"delete from comments where id = {commentID}")
Expand Down
6 changes: 3 additions & 3 deletions helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from random import randint
from os.path import exists
from datetime import datetime
from constants import LOG_FILE_ROOT
from constants import LOG_FILE_ROOT, DB_USERS_ROOT, DB_POSTS_ROOT, DB_COMMENTS_ROOT
from email.message import EmailMessage
from passlib.hash import sha256_crypt
from flask import render_template, Blueprint
Expand Down Expand Up @@ -67,7 +67,7 @@ def message(color, message):


def addPoints(points, user):
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'update users set points = points+{points} where userName = "{user}"'
Expand All @@ -77,7 +77,7 @@ def addPoints(points, user):


def getProfilePicture(userName):
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select profilePicture from users where lower(userName) = "{userName.lower()}"'
Expand Down
9 changes: 5 additions & 4 deletions routes/accountSettings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from helpers import (
request,
sqlite3,
session,
redirect,
render_template,
Blueprint,
request,
sqlite3,
DB_USERS_ROOT,
render_template,
)
from delete import deleteUser

Expand All @@ -15,7 +16,7 @@
def accountSettings():
match "userName" in session:
case True:
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select userName from users where userName = "{session["userName"]}"'
Expand Down
11 changes: 9 additions & 2 deletions routes/adminPanel.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
from helpers import sqlite3, render_template, Blueprint, session, redirect
from helpers import (
sqlite3,
session,
redirect,
Blueprint,
DB_USERS_ROOT,
render_template,
)

adminPanelBlueprint = Blueprint("adminPanel", __name__)

Expand All @@ -7,7 +14,7 @@
def adminPanel():
match "userName" in session:
case True:
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select role from users where userName = "{session["userName"]}"'
Expand Down
12 changes: 7 additions & 5 deletions routes/adminPanelComments.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from helpers import (
request,
sqlite3,
render_template,
Blueprint,
session,
redirect,
request,
Blueprint,
DB_USERS_ROOT,
render_template,
DB_COMMENTS_ROOT,
)
from delete import deleteComment

Expand All @@ -16,7 +18,7 @@
def adminPanelComments():
match "userName" in session:
case True:
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select role from users where userName = "{session["userName"]}"'
Expand All @@ -28,7 +30,7 @@ def adminPanelComments():
return redirect(f"/admin/comments")
match role == "admin":
case True:
connection = sqlite3.connect("db/comments.db")
connection = sqlite3.connect(DB_COMMENTS_ROOT)
cursor = connection.cursor()
cursor.execute("select * from comments")
comments = cursor.fetchall()
Expand Down
12 changes: 7 additions & 5 deletions routes/adminPanelPosts.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
from helpers import (
sqlite3,
render_template,
Blueprint,
session,
redirect,
request,
redirect,
Blueprint,
DB_POSTS_ROOT,
DB_USERS_ROOT,
render_template,
)
from delete import deletePost

Expand All @@ -16,7 +18,7 @@
def adminPanelPosts():
match "userName" in session:
case True:
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select role from users where userName = "{session["userName"]}"'
Expand All @@ -27,7 +29,7 @@ def adminPanelPosts():
deletePost(request.form["postID"])
match role == "admin":
case True:
connection = sqlite3.connect("db/posts.db")
connection = sqlite3.connect(DB_POSTS_ROOT)
cursor = connection.cursor()
cursor.execute("select * from posts")
posts = cursor.fetchall()
Expand Down
11 changes: 6 additions & 5 deletions routes/adminPanelUsers.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from helpers import (
sqlite3,
render_template,
Blueprint,
session,
redirect,
request,
redirect,
Blueprint,
DB_USERS_ROOT,
render_template,
)
from delete import deleteUser

Expand All @@ -16,7 +17,7 @@
def adminPanelUsers():
match "userName" in session:
case True:
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select role from users where userName = "{session["userName"]}"'
Expand All @@ -27,7 +28,7 @@ def adminPanelUsers():
deleteUser(request.form["userName"])
match role == "admin":
case True:
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute("select * from users")
users = cursor.fetchall()
Expand Down
9 changes: 5 additions & 4 deletions routes/changePassword.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from helpers import (
flash,
session,
sqlite3,
request,
flash,
message,
redirect,
render_template,
Blueprint,
sha256_crypt,
DB_USERS_ROOT,
render_template,
changePasswordForm,
)

Expand All @@ -23,7 +24,7 @@ def changePassword():
oldPassword = request.form["oldPassword"]
password = request.form["password"]
passwordConfirm = request.form["passwordConfirm"]
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select password from users where userName = "{session["userName"]}"'
Expand All @@ -35,7 +36,7 @@ def changePassword():
flash("passwords must match", "error")
elif oldPassword != password and password == passwordConfirm:
newPassword = sha256_crypt.hash(password)
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'update users set password = "{newPassword}" where userName = "{session["userName"]}"'
Expand Down
7 changes: 4 additions & 3 deletions routes/changeProfilePicture.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from helpers import (
flash,
session,
sqlite3,
request,
flash,
message,
redirect,
render_template,
Blueprint,
DB_USERS_ROOT,
render_template,
changeProfilePictureForm,
)

Expand All @@ -21,7 +22,7 @@ def changeProfilePicture():
if request.method == "POST":
newProfilePictureSeed = request.form["newProfilePictureSeed"]
newProfilePicture = f"https://api.dicebear.com/7.x/identicon/svg?seed={newProfilePictureSeed}&radius=10"
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'update users set profilePicture = "{newProfilePicture}" where userName = "{session["userName"]}" '
Expand Down
13 changes: 8 additions & 5 deletions routes/changeUserName.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from helpers import (
flash,
session,
sqlite3,
request,
flash,
message,
redirect,
render_template,
Blueprint,
DB_POSTS_ROOT,
DB_USERS_ROOT,
render_template,
DB_COMMENTS_ROOT,
changeUserNameForm,
)

Expand All @@ -21,7 +24,7 @@ def changeUserName():
if request.method == "POST":
newUserName = request.form["newUserName"]
newUserName = newUserName.replace(" ", "")
connection = sqlite3.connect("db/users.db")
connection = sqlite3.connect(DB_USERS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'select userName from users where userName = "{newUserName}"'
Expand All @@ -39,13 +42,13 @@ def changeUserName():
f'update users set userName = "{newUserName}" where userName = "{session["userName"]}" '
)
connection.commit()
connection = sqlite3.connect("db/posts.db")
connection = sqlite3.connect(DB_POSTS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'update posts set Author = "{newUserName}" where author = "{session["userName"]}" '
)
connection.commit()
connection = sqlite3.connect("db/comments.db")
connection = sqlite3.connect(DB_COMMENTS_ROOT)
cursor = connection.cursor()
cursor.execute(
f'update comments set user = "{newUserName}" where user = "{session["userName"]}" '
Expand Down
9 changes: 5 additions & 4 deletions routes/createPost.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
from helpers import (
flash,
session,
sqlite3,
request,
flash,
message,
redirect,
addPoints,
Blueprint,
currentDate,
currentTime,
render_template,
Blueprint,
DB_POSTS_ROOT,
createPostForm,
render_template,
)

createPostBlueprint = Blueprint("createPost", __name__)
Expand All @@ -33,7 +34,7 @@ def createPost():
f'POST CONTENT NOT BE EMPTY USER: "{session["userName"]}"',
)
case False:
connection = sqlite3.connect("db/posts.db")
connection = sqlite3.connect(DB_POSTS_ROOT)
cursor = connection.cursor()
cursor.execute(
"insert into posts(title,tags,content,author,views,date,time,lastEditDate,lastEditTime) \
Expand Down
Loading

0 comments on commit 967abe1

Please sign in to comment.