From cd749031843231583fd42b588a51fd260ec4e4a1 Mon Sep 17 00:00:00 2001 From: bacalhau Date: Tue, 3 Mar 2026 23:49:50 +0000 Subject: [PATCH] added a rudimentary user page --- src/main.py | 61 ++++++++++++++++++++++++------------- src/templates/register.html | 26 ++++++++++------ src/templates/user.html | 37 ++++++++++++++++++++++ 3 files changed, 93 insertions(+), 31 deletions(-) create mode 100644 src/templates/user.html diff --git a/src/main.py b/src/main.py index eb22709..c664e7f 100644 --- a/src/main.py +++ b/src/main.py @@ -4,21 +4,42 @@ from datetime import date import gnupg import secrets -app = Flask(__name__) +COUNTRIES = [ + "Afghanistan","Albania","Algeria","Andorra","Angola","Antigua and Barbuda","Argentina","Armenia","Australia","Austria", + "Azerbaijan","Bahamas","Bahrain","Bangladesh","Barbados","Belarus","Belgium","Belize","Benin","Bhutan", + "Bolivia","Bosnia and Herzegovina","Botswana","Brazil","Brunei","Bulgaria","Burkina Faso","Burundi","Cabo Verde","Cambodia", + "Cameroon","Canada","Central African Republic","Chad","Chile","China","Colombia","Comoros","Congo (Congo-Brazzaville)","Costa Rica", + "Croatia","Cuba","Cyprus","Czechia (Czech Republic)","Democratic Republic of the Congo","Denmark","Djibouti","Dominica","Dominican Republic","Ecuador", + "Egypt","El Salvador","Equatorial Guinea","Eritrea","Estonia","Eswatini (fmr. Swaziland)","Ethiopia","Fiji","Finland","France", + "Gabon","Gambia","Georgia","Germany","Ghana","Greece","Grenada","Guatemala","Guinea","Guinea-Bissau", + "Guyana","Haiti","Holy See","Honduras","Hungary","Iceland","India","Indonesia","Iran","Iraq", + "Ireland","Israel","Italy","Jamaica","Japan","Jordan","Kazakhstan","Kenya","Kiribati","Kuwait", + "Kyrgyzstan","Laos","Latvia","Lebanon","Lesotho","Liberia","Libya","Liechtenstein","Lithuania","Luxembourg", + "Madagascar","Malawi","Malaysia","Maldives","Mali","Malta","Marshall Islands","Mauritania","Mauritius","Mexico", + "Micronesia","Moldova","Monaco","Mongolia","Montenegro","Morocco","Mozambique","Myanmar (Burma)","Namibia","Nauru", + "Nepal","Netherlands","New Zealand","Nicaragua","Niger","Nigeria","North Korea","North Macedonia","Norway","Oman", + "Pakistan","Palau","Palestine State","Panama","Papua New Guinea","Paraguay","Peru","Philippines","Poland","Portugal", + "Qatar","Romania","Russia","Rwanda","Saint Kitts and Nevis","Saint Lucia","Saint Vincent and the Grenadines","Samoa","San Marino","Sao Tome and Principe", + "Saudi Arabia","Senegal","Serbia","Seychelles","Sierra Leone","Singapore","Slovakia","Slovenia","Solomon Islands","Somalia", + "South Africa","South Korea","South Sudan","Spain","Sri Lanka","Sudan","Suriname","Sweden","Switzerland","Syria", + "Tajikistan","Tanzania","Thailand","Timor-Leste","Togo","Tonga","Trinidad and Tobago","Tunisia","Turkey","Turkmenistan", + "Tuvalu","Uganda","Ukraine","United Arab Emirates","United Kingdom","United States","Uruguay","Uzbekistan","Vanuatu","Venezuela", + "Vietnam","Yemen","Zambia","Zimbabwe" +] +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' -gpg = gnupg.GPG() - db = SQLAlchemy(app) +gpg = gnupg.GPG() class User(db.Model): id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(128), unique=True, nullable=False) - pgp = db.Column(db.String(8128), nullable=False) + pgp = db.Column(db.String(4096), nullable=False) firstname = db.Column(db.String(128), nullable=False) lastname = db.Column(db.String(128), nullable=False) @@ -55,7 +76,6 @@ def home(): @app.route("/register", methods=["GET", "POST"]) def register(): if request.method == "POST": - username = request.form.get("username") pgp = request.form.get("pgp") firstname = request.form.get("firstname") @@ -74,8 +94,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, profile_picture, country, xmpp]): flash("Please fill all required fields.") return redirect(url_for("register")) @@ -128,7 +147,7 @@ def register(): import_result = gpg.import_keys(pgp) if not import_result.fingerprints: - flash("Invalid PGP key. Make sure you pasted the full ASCII-armored public key.") + flash("Invalid PGP key.") return redirect(url_for("register")) fingerprint = import_result.fingerprints[0] @@ -136,23 +155,15 @@ def register(): random_string = secrets.token_hex(16) challenge_phrase = f"this is the unencrypted string: {random_string}" - encrypted_data = gpg.encrypt( - challenge_phrase, - recipients=[fingerprint] - ) - + encrypted_data = gpg.encrypt(challenge_phrase, recipients=[fingerprint]) if not encrypted_data.ok: - flash("Failed to encrypt challenge. Check your PGP key.") + flash("Failed to encrypt challenge.") return redirect(url_for("register")) session["pgp_expected_phrase"] = challenge_phrase + return render_template("verify.html", encrypted_message=str(encrypted_data)) - return render_template( - "verify.html", - encrypted_message=str(encrypted_data) - ) - - return render_template("register.html") + return render_template("register.html", countries=COUNTRIES) @app.route("/verify", methods=["POST"]) def verify(): @@ -188,7 +199,7 @@ def verify(): weight=int(data["weight"]) if data["weight"] else None, race=data["race"] or None, prefered_age_range=data["prefered_age_range"] or None, - is_verified=False + is_verified=True ) db.session.add(new_user) @@ -200,7 +211,7 @@ def verify(): session.pop("pending_user", None) session.pop("pgp_expected_phrase", None) - flash("PGP verification successful!") + flash("PGP verification successful! Account created.") return redirect(url_for("home")) else: @@ -286,6 +297,12 @@ def logout(): flash("Logged out successfully") return redirect(url_for("home")) +@app.route("/user/") +def user_profile(username): + user = User.query.filter_by(username=username).first_or_404() + + return render_template("user.html", user=user, date=date) + if __name__ == "__main__": with app.app_context(): db.create_all() diff --git a/src/templates/register.html b/src/templates/register.html index 8e19d76..61dbbb4 100644 --- a/src/templates/register.html +++ b/src/templates/register.html @@ -6,26 +6,34 @@

Identity

-
-
+ *
+ *

Personal Info

-
-
+ *
+ *

+ *
-
+ *
-

Profile

-
+

Profile Picture

+ *
+ +

Other Pictures

+

Location

-
+ *

Physical Attributes

diff --git a/src/templates/user.html b/src/templates/user.html new file mode 100644 index 0000000..cfa71bf --- /dev/null +++ b/src/templates/user.html @@ -0,0 +1,37 @@ +{% extends "page.html" %} + +{% block content %} +

{{ user.firstname }} {{ user.lastname }}

+Profile Picture
+ +{% if user.pictures %} +

Pictures

+{% for pic in user.pictures %} + +{% endfor %} +{% endif %} + +

Personal Info

+

Sex: {{ user.sex }}

+

Date of Birth: {{ user.date_of_birth }}

+

Age: {{ (date.today() - user.date_of_birth).days // 365 }}

+

Race: {{ user.race or 'Not specified' }}

+ +

Location

+

Country: {{ user.country }}

+

City: {{ user.city or 'Not specified' }}

+ +

Physical Attributes

+

Height: {{ user.height or 'Not specified' }} m

+

Weight: {{ user.weight or 'Not specified' }} kg

+ +

Preferences

+

Preferred Age Range: {{ user.prefered_age_range or 'Not specified' }}

+

Likes: {{ user.likes | join(', ') if user.likes else 'Not specified' }}

+

Dislikes: {{ user.dislikes | join(', ') if user.dislikes else 'Not specified' }}

+ +

Contacts

+

XMPP: {{ user.xmpp }}

+

Email: {{ user.email or 'Not specified' }}

+

Phone: {{ user.phone or 'Not specified' }}

+{% endblock %}