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 functools import wraps
|
||||||
|
|
||||||
from core.forms import SignupForm, LoginForm
|
from core.forms import SignupForm, LoginForm
|
||||||
from core.database import Database
|
from database.database import Database
|
||||||
|
|
||||||
app = Flask(__name__, template_folder="../ui/templates/")
|
app = Flask(__name__, template_folder="../ui/templates/")
|
||||||
app.config["SECRET_KEY"] = ""
|
app.config["SECRET_KEY"] = ""
|
||||||
app.config["SESSION_PERMANENT"] = False
|
app.config["SESSION_PERMANENT"] = False
|
||||||
app.config["SESSION_TYPE"] = "filesystem"
|
app.config["SESSION_TYPE"] = "filesystem"
|
||||||
app.teardown_appcontext(Database.close_connection)
|
|
||||||
Session(app)
|
Session(app)
|
||||||
|
|
||||||
@app.before_request
|
@app.before_request
|
||||||
@@ -58,7 +58,7 @@ def signup():
|
|||||||
|
|
||||||
# Store in database and hash to avoid exposing sensitive information
|
# Store in database and hash to avoid exposing sensitive information
|
||||||
db = Database()
|
db = Database()
|
||||||
cursor = db.create_connection("../database/app.db")
|
cursor = db.create_connection()
|
||||||
|
|
||||||
# Check if user already exists to avoid duplicates
|
# Check if user already exists to avoid duplicates
|
||||||
dup_email = cursor.execute("""SELECT * FROM users
|
dup_email = cursor.execute("""SELECT * FROM users
|
||||||
@@ -73,9 +73,9 @@ def signup():
|
|||||||
elif password != password2:
|
elif password != password2:
|
||||||
form.password.errors.append("Passwords must match.")
|
form.password.errors.append("Passwords must match.")
|
||||||
else:
|
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."))
|
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"))
|
return redirect(url_for("login"))
|
||||||
|
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ def login():
|
|||||||
|
|
||||||
# Compare with database
|
# Compare with database
|
||||||
db = 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
|
# Check if user exists so only users who have signed up can login
|
||||||
user_exists = cursor.execute("""SELECT * FROM users
|
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()
|
|
||||||
BIN
database/__pycache__/database.cpython-310.pyc
Normal file
BIN
database/__pycache__/database.cpython-310.pyc
Normal file
Binary file not shown.
BIN
database/app.db
BIN
database/app.db
Binary file not shown.
22
database/database.py
Normal file
22
database/database.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
|
||||||
|
class Database:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
self._db = os.path.join(os.path.abspath(os.path.dirname(__file__)), "app.db")
|
||||||
|
|
||||||
|
def create_connection(self) -> sqlite3.Cursor:
|
||||||
|
conn = sqlite3.connect(self._db)
|
||||||
|
conn.row_factory = sqlite3.Row
|
||||||
|
self._conn = conn
|
||||||
|
cursor = conn.cursor()
|
||||||
|
return cursor
|
||||||
|
|
||||||
|
def commit_data(self):
|
||||||
|
try:
|
||||||
|
self._conn.commit()
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
|
||||||
|
def close_connection(self) -> None:
|
||||||
|
self._conn.close()
|
||||||
@@ -5,10 +5,13 @@ CREATE TABLE users
|
|||||||
password VARCHAR(256) NOT NULL,
|
password VARCHAR(256) NOT NULL,
|
||||||
email VARCHAR(64) NOT NULL,
|
email VARCHAR(64) NOT NULL,
|
||||||
num_followers INTEGER NOT NULL,
|
num_followers INTEGER NOT NULL,
|
||||||
isPartenered BOOLEAN NOT NULL DEFAULT 0
|
isPartenered BOOLEAN NOT NULL DEFAULT 0,
|
||||||
bio TEXT,
|
bio TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
SELECT * FROM users;
|
||||||
|
|
||||||
|
|
||||||
DROP TABLE IF EXISTS streams;
|
DROP TABLE IF EXISTS streams;
|
||||||
CREATE TABLE streams
|
CREATE TABLE streams
|
||||||
(
|
(
|
||||||
|
|||||||
BIN
flask_session/2029240f6d1128be89ddc32729463129
Normal file
BIN
flask_session/2029240f6d1128be89ddc32729463129
Normal file
Binary file not shown.
BIN
flask_session/841e29f4900cf96cfb8ec55c0c598d2c
Normal file
BIN
flask_session/841e29f4900cf96cfb8ec55c0c598d2c
Normal file
Binary file not shown.
@@ -1,20 +1,5 @@
|
|||||||
{% extends "base.html" %}
|
{% extends "base.html" %}
|
||||||
|
|
||||||
{% block main_content %}
|
{% block main_content %}
|
||||||
<h1>Live Stream</h1>
|
<h1>Welcome</h1>
|
||||||
<video id="localVideo" autoplay playsinline controls></video>
|
|
||||||
<script>
|
|
||||||
// constant containing the video
|
|
||||||
const videoElement = document.getElementById('localVideo');
|
|
||||||
|
|
||||||
// Request access to the user's camera and microphone
|
|
||||||
navigator.mediaDevices.getUserMedia({ video: true, audio: true })
|
|
||||||
.then((stream) => {
|
|
||||||
// Display the stream locally
|
|
||||||
videoElement.srcObject = stream;
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error('Error accessing media devices.', error);
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
19
ui/templates/login.html
Normal file
19
ui/templates/login.html
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block main_content %}
|
||||||
|
<form action="" method="post" novalidate>
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ form.username.label }}
|
||||||
|
{{ form.username() }}
|
||||||
|
{% for error in form.username.errors %}
|
||||||
|
{{ error }}
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{{ form.password.label }}
|
||||||
|
{{ form.password() }}
|
||||||
|
<br />
|
||||||
|
{{ form.submit() }}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
31
ui/templates/signup.html
Normal file
31
ui/templates/signup.html
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block main_content %}
|
||||||
|
|
||||||
|
<form action="" method="post" novalidate>
|
||||||
|
{{ form.hidden_tag() }}
|
||||||
|
{{ form.email.label }}
|
||||||
|
{{ form.email() }}
|
||||||
|
{% for error in form.email.errors %}
|
||||||
|
{{ error }}
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{{ form.username.label }}
|
||||||
|
{{ form.username() }}
|
||||||
|
{% for error in form.username.errors %}
|
||||||
|
{{ error }}
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{{ form.password.label }}
|
||||||
|
{{ form.password() }}
|
||||||
|
{% for error in form.password.errors %}
|
||||||
|
{{ error }}
|
||||||
|
{% endfor %}
|
||||||
|
<br />
|
||||||
|
{{ form.password2.label }}
|
||||||
|
{{ form.password2() }}
|
||||||
|
<br />
|
||||||
|
{{ form.submit() }}
|
||||||
|
</form>
|
||||||
|
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user