Pixel pulse #169485
Replies: 2 comments
-
|
Hello, I've reviewed your code. It's a great starting point for building a Flask app, but it has some important security and functionality issues that need to be addressed before it can be used for a real application. The main problems were: Security: Passwords were stored in plain text, and anyone could upload a video without logging in. Functionality: The app didn't remember if a user was logged in, and it had minor syntax errors that prevented it from running correctly. I've rewritten the code to fix these issues. This version is more secure and reliable. Key Improvements in the New Code User Sessions: The app now uses a session to remember who a user is after they log in. This allows you to protect certain pages. Protected Routes: The /upload page is now protected, and you can only access it if you are logged in. Correct Syntax: Minor syntax errors (name was changed to name) were fixed so the code runs without issues. Logout Functionality: A new /logout route was added to allow users to end their session. Here is the corrected and more secure code. I've also included a small note on how to update your HTML to take advantage of these new features. Hope this helps! |
Beta Was this translation helpful? Give feedback.
-
|
🕒 Discussion Activity Reminder 🕒 This Discussion has been labeled as dormant by an automated system for having no activity in the last 60 days. Please consider one the following actions: 1️⃣ Close as Out of Date: If the topic is no longer relevant, close the Discussion as 2️⃣ Provide More Information: Share additional details or context — or let the community know if you've found a solution on your own. 3️⃣ Mark a Reply as Answer: If your question has been answered by a reply, mark the most helpful reply as the solution. Note: This dormant notification will only apply to Discussions with the Thank you for helping bring this Discussion to a resolution! 💬 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Select Topic Area
Question
Body
from flask import Flask, render_template, request, redirect, url_for
app = Flask(name)
Dummy user store
users = {}
videos = []
@app.route('/')
def index():
return render_template("index.html", videos=videos)
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
if username in users and users[username] == password:
return redirect(url_for('index'))
return "Invalid credentials"
return render_template("login.html")
@app.route('/signup', methods=['GET', 'POST'])
def signup():
if request.method == 'POST':
username = request.form['username']
password = request.form['password']
users[username] = password
return redirect(url_for('login'))
return render_template("signup.html")
@app.route('/upload', methods=['GET', 'POST'])
def upload():
if request.method == 'POST':
title = request.form['title']
link = request.form['link']
videos.append({"title": title, "link": link})
return redirect(url_for('index'))
return render_template("upload.html")
if name == 'main':
<title>Pixel Pulse</title>app.run(debug=True)flaskweb: python app.py
Pixel Pulse
Login | Sign Up | Upload VideoSearch
Videos
{% for video in videos %}{{ video.title }} - Watch
{% endfor %} <title>Login - Pixel Pulse</title>Login
Username:Password:
Login <title>Sign Up - Pixel Pulse</title>
Sign Up
Username:Password:
Sign Up <title>Upload Video - Pixel Pulse</title>
Upload Video
Title:Video Link:
Upload body { font-family: Arial, sans-serif; margin: 20px; } input, button { margin: 5px; `}`
Beta Was this translation helpful? Give feedback.
All reactions