Improved login funtion by creating temporary HTML pages and fixing bugs in login
This commit is contained in:
Binary file not shown.
BIN
core/__pycache__/database.cpython-310.pyc
Normal file
BIN
core/__pycache__/database.cpython-310.pyc
Normal file
Binary file not shown.
12
core/app.py
12
core/app.py
@@ -4,13 +4,13 @@ from werkzeug.security import generate_password_hash, check_password_hash
|
||||
from functools import wraps
|
||||
|
||||
from core.forms import SignupForm, LoginForm
|
||||
from core.database import Database
|
||||
from database.database import Database
|
||||
|
||||
app = Flask(__name__, template_folder="../ui/templates/")
|
||||
app.config["SECRET_KEY"] = ""
|
||||
app.config["SESSION_PERMANENT"] = False
|
||||
app.config["SESSION_TYPE"] = "filesystem"
|
||||
app.teardown_appcontext(Database.close_connection)
|
||||
|
||||
Session(app)
|
||||
|
||||
@app.before_request
|
||||
@@ -58,7 +58,7 @@ def signup():
|
||||
|
||||
# Store in database and hash to avoid exposing sensitive information
|
||||
db = Database()
|
||||
cursor = db.create_connection("../database/app.db")
|
||||
cursor = db.create_connection()
|
||||
|
||||
# Check if user already exists to avoid duplicates
|
||||
dup_email = cursor.execute("""SELECT * FROM users
|
||||
@@ -73,9 +73,9 @@ def signup():
|
||||
elif password != password2:
|
||||
form.password.errors.append("Passwords must match.")
|
||||
else:
|
||||
db.execute("""INSERT INTO users (username, password, email, num_followers, isPartenered, bio)
|
||||
cursor.execute("""INSERT INTO users (username, password, email, num_followers, isPartenered, bio)
|
||||
VALUES (?, ?, ?, ?, ?, ?);""", (username, generate_password_hash(password), email, 0, 0, "This user does not have a Bio."))
|
||||
db.commit()
|
||||
db.commit_data()
|
||||
return redirect(url_for("login"))
|
||||
|
||||
|
||||
@@ -94,7 +94,7 @@ def login():
|
||||
|
||||
# Compare with database
|
||||
db = Database()
|
||||
cursor = db.create_connection("../database/app.db")
|
||||
cursor = db.create_connection()
|
||||
|
||||
# Check if user exists so only users who have signed up can login
|
||||
user_exists = cursor.execute("""SELECT * FROM users
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
import sqlite3
|
||||
|
||||
class Database:
|
||||
def __init__(self, db:str) -> None:
|
||||
self._db = db
|
||||
self._conn = None
|
||||
|
||||
def create_connection(self) -> sqlite3.Cursor:
|
||||
conn = sqlite3.connect(self._db)
|
||||
self._conn = conn
|
||||
cursor = conn.cursor()
|
||||
return cursor
|
||||
|
||||
def close_connection(self) -> None:
|
||||
self._conn.close()
|
||||
Reference in New Issue
Block a user