UPDATE: Added stream title and selected category to users table

This commit is contained in:
2025-01-29 00:38:10 +00:00
parent 252ca7d1e6
commit bc1a48a571
5 changed files with 29 additions and 16 deletions

View File

@@ -3,6 +3,7 @@ from werkzeug.security import generate_password_hash, check_password_hash
from flask_cors import cross_origin from flask_cors import cross_origin
from database.database import Database from database.database import Database
from blueprints.utils import login_required, sanitizer from blueprints.utils import login_required, sanitizer
from secrets import token_hex
auth_bp = Blueprint("auth", __name__) auth_bp = Blueprint("auth", __name__)
@@ -78,16 +79,18 @@ def signup():
# Create new user once input is validated # Create new user once input is validated
cursor.execute( cursor.execute(
"""INSERT INTO users """INSERT INTO users
(username, password, email, num_followers, stream_key, is_partnered, bio) (username, password, email, num_followers, stream_key, is_partnered, bio, current_stream_title, current_selected_category_id)
VALUES (?, ?, ?, ?, ?, ?, ?)""", VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)""",
( (
username, username,
generate_password_hash(password), generate_password_hash(password),
email, email,
0, 0,
'1', token_hex(32),
0, 0,
"This user does not have a Bio." "This user does not have a Bio.",
"My Stream",
None
) )
) )
db.commit_data() db.commit_data()

View File

@@ -181,11 +181,18 @@ def publish_stream():
# Check if stream key is valid # Check if stream key is valid
db = Database() db = Database()
db.create_connection() db.create_connection()
stream = db.fetchone("SELECT username FROM users WHERE stream_key = ?", (stream_key,)) user_info = db.fetchone("""SELECT user_id, username
FROM users
WHERE stream_key = ?""", (stream_key,))
## TODO: Add stream to database if not user_info:
if not stream:
return "Unauthorized", 403 return "Unauthorized", 403
return redirect(f"/{stream['username']}") return redirect(f"/{user_info['username']}")
@stream_bp.route("/end_stream", methods=["POST"])
def end_stream():
"""
Ends a stream
"""
return

Binary file not shown.

View File

@@ -7,12 +7,12 @@ INSERT INTO categories (category_name) VALUES
('Sports'); ('Sports');
-- Sample data for users -- Sample data for users
INSERT INTO users (username, password, email, num_followers, stream_key, is_partnered, bio) VALUES INSERT INTO users (username, password, email, num_followers, stream_key, is_partnered, bio, current_stream_title, current_selected_category_id) VALUES
('GamerDude', 'password123', 'gamerdude@example.com', 500, '1234', 0, 'Streaming my gaming adventures!'), ('GamerDude', 'password123', 'gamerdude@example.com', 500, '1234', 0, 'Streaming my gaming adventures!', 'Epic Gaming Session', 1),
('MusicLover', 'music4life', 'musiclover@example.com', 1200, '2345', 0, 'I share my favorite tunes.'), ('MusicLover', 'music4life', 'musiclover@example.com', 1200, '2345', 0, 'I share my favorite tunes.', 'Live Music Jam', 2),
('ArtFan', 'artistic123', 'artfan@example.com', 300, '3456', 0, 'Exploring the world of art.'), ('ArtFan', 'artistic123', 'artfan@example.com', 300, '3456', 0, 'Exploring the world of art.', 'Sketching Live', 3),
('EduGuru', 'learn123', 'eduguru@example.com', 800, '4567', 0, 'Teaching everything I know.'), ('EduGuru', 'learn123', 'eduguru@example.com', 800, '4567', 0, 'Teaching everything I know.', 'Math Made Easy', 4),
('SportsStar', 'sports123', 'sportsstar@example.com', 2000, '5678', 0, 'Join me for live sports updates!'); ('SportsStar', 'sports123', 'sportsstar@example.com', 2000, '5678', 0, 'Join me for live sports updates!', 'Sports Highlights', 5);
-- Sample data for streams -- Sample data for streams
INSERT INTO streams (user_id, title, start_time, num_viewers, isLive, vod_id, category_id) VALUES INSERT INTO streams (user_id, title, start_time, num_viewers, isLive, vod_id, category_id) VALUES

View File

@@ -11,7 +11,10 @@ CREATE TABLE users
num_followers INTEGER NOT NULL, num_followers INTEGER NOT NULL,
stream_key VARCHAR(60) NOT NULL, stream_key VARCHAR(60) NOT NULL,
is_partnered BOOLEAN NOT NULL DEFAULT 0, is_partnered BOOLEAN NOT NULL DEFAULT 0,
bio VARCHAR(1024) bio VARCHAR(1024),
current_stream_title VARCHAR(100),
current_selected_category_id INTEGER
); );
SELECT * FROM users; SELECT * FROM users;