added a rudimentary user page

This commit is contained in:
bacalhau 2026-03-03 23:49:50 +00:00
parent 2f24f28b82
commit cd74903184
3 changed files with 93 additions and 31 deletions

View file

@ -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/<username>")
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()