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

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)