added user pages

This commit is contained in:
bacalhau 2026-03-04 00:26:12 +00:00
parent cd74903184
commit c6448bcf55
9 changed files with 55 additions and 23 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
data
src/static/uploads

View file

@ -3,6 +3,12 @@ from flask_sqlalchemy import SQLAlchemy
from datetime import date
import gnupg
import secrets
import os
from werkzeug.utils import secure_filename
UPLOAD_FOLDER = "static/uploads"
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
COUNTRIES = [
"Afghanistan","Albania","Algeria","Andorra","Angola","Antigua and Barbuda","Argentina","Armenia","Australia","Austria",
@ -31,6 +37,7 @@ app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://love:love@localhost:3309/lovedb'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SECRET_KEY'] = 'random'
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
db = SQLAlchemy(app)
gpg = gnupg.GPG()
@ -82,7 +89,6 @@ def register():
lastname = request.form.get("lastname")
sex = request.form.get("sex")
date_of_birth = request.form.get("date_of_birth")
profile_picture = request.form.get("profile_picture")
country = request.form.get("country")
xmpp = request.form.get("xmpp")
@ -94,7 +100,7 @@ def register():
race = request.form.get("race")
prefered_age_range = request.form.get("prefered_age_range")
if not all([username, pgp, firstname, lastname, sex, date_of_birth, profile_picture, country, xmpp]):
if not all([username, pgp, firstname, lastname, sex, date_of_birth, country, xmpp]):
flash("Please fill all required fields.")
return redirect(url_for("register"))
@ -126,6 +132,30 @@ def register():
flash("You must be at least 18 years old to register.")
return redirect(url_for("register"))
profile_file = request.files.get("profile_picture")
pictures_files = request.files.getlist("pictures")
if not profile_file:
flash("Profile picture is required.")
return redirect(url_for("register"))
user_folder = os.path.join(app.root_path, "static/uploads", username)
os.makedirs(user_folder, exist_ok=True)
from werkzeug.utils import secure_filename
profile_filename = secure_filename(profile_file.filename)
profile_path = os.path.join(user_folder, profile_filename)
profile_file.save(profile_path)
profile_url = f"/static/uploads/{username}/{profile_filename}"
pictures_urls = []
for pic in pictures_files:
if pic.filename:
filename = secure_filename(pic.filename)
path = os.path.join(user_folder, filename)
pic.save(path)
pictures_urls.append(f"/static/uploads/{username}/{filename}")
session["pending_user"] = {
"username": username,
"pgp": pgp,
@ -133,7 +163,8 @@ def register():
"lastname": lastname,
"sex": sex,
"date_of_birth": date_of_birth,
"profile_picture": profile_picture,
"profile_url": profile_url,
"pictures_urls": pictures_urls,
"country": country,
"xmpp": xmpp,
"email": email,
@ -151,10 +182,8 @@ def register():
return redirect(url_for("register"))
fingerprint = import_result.fingerprints[0]
random_string = secrets.token_hex(16)
challenge_phrase = f"this is the unencrypted string: {random_string}"
encrypted_data = gpg.encrypt(challenge_phrase, recipients=[fingerprint])
if not encrypted_data.ok:
flash("Failed to encrypt challenge.")
@ -189,7 +218,8 @@ def verify():
lastname=data["lastname"],
sex=data["sex"],
date_of_birth=dob,
profile_picture=data["profile_picture"],
profile_picture=data["profile_url"],
pictures=data["pictures_urls"],
country=data["country"],
xmpp=data["xmpp"],
email=data["email"] or None,
@ -208,6 +238,7 @@ def verify():
session['user_id'] = new_user.id
session['username'] = new_user.username
# limpar dados temporários
session.pop("pending_user", None)
session.pop("pgp_expected_phrase", None)

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 MiB

View file

@ -3,48 +3,48 @@
{% block content %}
<h2>Register</h2>
<form method="POST">
<form method="POST" enctype="multipart/form-data">
<h3>Identity</h3>
<input type="text" name="username" placeholder="Username" required>*<br>
<textarea name="pgp" placeholder="PGP Public Key" required></textarea>*<br>
<h3>Identity (required)</h3>
<input type="text" name="username" placeholder="Username" required><br>
<textarea name="pgp" placeholder="PGP Public Key" required></textarea><br>
<h3>Personal Info</h3>
<input type="text" name="firstname" placeholder="First Name" required>*<br>
<input type="text" name="lastname" placeholder="Last Name" required>*<br>
<h3>Personal Info (required)</h3>
<input type="text" name="firstname" placeholder="First Name" required><br>
<input type="text" name="lastname" placeholder="Last Name" required><br>
<select name="sex" required>
<option value="">Select Sex</option>
<option value="male">Male</option>
<option value="female">Female</option>
</select>*<br>
</select><br>
<input type="date" name="date_of_birth" required>*<br>
<input type="date" name="date_of_birth" required><br>
<h3>Profile Picture</h3>
<input type="file" name="profile_picture" accept="image/*" required>*<br>
<h3>Profile Picture (required)</h3>
<input type="file" name="profile_picture" accept="image/*" required><br>
<h3>Other Pictures</h3>
<h3>Other Pictures (optional, multiple)</h3>
<input type="file" name="pictures" accept="image/*" multiple><br>
<h3>Location</h3>
<h3>Location (required)</h3>
<select name="country" required>
<option value="">Select Country</option>
{% for c in countries %}
<option value="{{ c }}">{{ c }}</option>
{% endfor %}
</select>*<br>
</select><br>
<input type="text" name="city" placeholder="City"><br>
<h3>Physical Attributes</h3>
<h3>Physical Attributes (optional)</h3>
<input type="number" step="0.01" name="height" placeholder="Height (m)"><br>
<input type="number" name="weight" placeholder="Weight (kg)"><br>
<input type="text" name="race" placeholder="Race"><br>
<h3>Preferences</h3>
<h3>Preferences (optional)</h3>
<input type="text" name="prefered_age_range" placeholder="Preferred Age Range (e.g. 20-30)"><br>
<h3>Contacts</h3>
<h3>Contacts (required)</h3>
<input type="text" name="xmpp" placeholder="XMPP" required><br>
<input type="email" name="email" placeholder="Email"><br>
<input type="text" name="phone" placeholder="Phone"><br><br>