Update app.py
This commit is contained in:
@@ -23,18 +23,15 @@ with app.app_context():
|
||||
def handle_submission():
|
||||
form_username = request.form.get('username')
|
||||
form_email = request.form.get('email')
|
||||
form_password = request.form.get('password') # 1. Grab password from HTML
|
||||
form_password = request.form.get('password')
|
||||
|
||||
# Check for duplicates
|
||||
if User.query.filter_by(username=form_username).first():
|
||||
return "<h3>Username taken!</h3>", 400
|
||||
if User.query.filter_by(email=form_email).first():
|
||||
return "<h3>Email already registered!</h3>", 400
|
||||
|
||||
# 2. Hash the password into a secure scramble
|
||||
hashed_password = generate_password_hash(form_password)
|
||||
|
||||
# 3. Save the user with the scrambled hash
|
||||
new_user = User(username=form_username, email=form_email, password_hash=hashed_password)
|
||||
db.session.add(new_user)
|
||||
db.session.commit()
|
||||
@@ -47,10 +44,8 @@ def success():
|
||||
|
||||
@app.route('/users')
|
||||
def view_users():
|
||||
# Fetch all user records from the database
|
||||
all_users = User.query.all()
|
||||
|
||||
# Create a simple HTML table to display them nicely
|
||||
html_output = "<h2>Registered Accounts</h2><table border='1' cellpadding='10'>"
|
||||
html_output += "<tr><th>ID</th><th>Username</th><th>Email</th></tr>"
|
||||
|
||||
@@ -59,7 +54,6 @@ def view_users():
|
||||
|
||||
html_output += "</table>"
|
||||
|
||||
# If the database is completely empty
|
||||
if not all_users:
|
||||
return "<h3>No accounts found in the database yet.</h3>"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user