diff --git a/.gitignore b/.gitignore index 1269488..0516b64 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ data +src/static/uploads diff --git a/src/main.py b/src/main.py index c664e7f..5cd18e8 100644 --- a/src/main.py +++ b/src/main.py @@ -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) diff --git a/src/static/uploads/bacalhau/DSCF6156.JPG b/src/static/uploads/bacalhau/DSCF6156.JPG new file mode 100644 index 0000000..cd7a77d Binary files /dev/null and b/src/static/uploads/bacalhau/DSCF6156.JPG differ diff --git a/src/static/uploads/bacalhau/DSCF6158.JPG b/src/static/uploads/bacalhau/DSCF6158.JPG new file mode 100644 index 0000000..df5345f Binary files /dev/null and b/src/static/uploads/bacalhau/DSCF6158.JPG differ diff --git a/src/static/uploads/bacalhau/DSCF6162.JPG b/src/static/uploads/bacalhau/DSCF6162.JPG new file mode 100644 index 0000000..17442fa Binary files /dev/null and b/src/static/uploads/bacalhau/DSCF6162.JPG differ diff --git a/src/static/uploads/bacalhau/DSCF6168.JPG b/src/static/uploads/bacalhau/DSCF6168.JPG new file mode 100644 index 0000000..8b18fdf Binary files /dev/null and b/src/static/uploads/bacalhau/DSCF6168.JPG differ diff --git a/src/static/uploads/bacalhau/DSCF6170.JPG b/src/static/uploads/bacalhau/DSCF6170.JPG new file mode 100644 index 0000000..c42cc0a Binary files /dev/null and b/src/static/uploads/bacalhau/DSCF6170.JPG differ diff --git a/src/static/uploads/bacalhau/DSCF6242.JPG b/src/static/uploads/bacalhau/DSCF6242.JPG new file mode 100644 index 0000000..0a02c65 Binary files /dev/null and b/src/static/uploads/bacalhau/DSCF6242.JPG differ diff --git a/src/templates/register.html b/src/templates/register.html index 61dbbb4..8cf7492 100644 --- a/src/templates/register.html +++ b/src/templates/register.html @@ -3,48 +3,48 @@ {% block content %}