added user pages
This commit is contained in:
parent
cd74903184
commit
c6448bcf55
9 changed files with 55 additions and 23 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1 +1,2 @@
|
||||||
data
|
data
|
||||||
|
src/static/uploads
|
||||||
|
|
|
||||||
43
src/main.py
43
src/main.py
|
|
@ -3,6 +3,12 @@ from flask_sqlalchemy import SQLAlchemy
|
||||||
from datetime import date
|
from datetime import date
|
||||||
import gnupg
|
import gnupg
|
||||||
import secrets
|
import secrets
|
||||||
|
import os
|
||||||
|
from werkzeug.utils import secure_filename
|
||||||
|
|
||||||
|
|
||||||
|
UPLOAD_FOLDER = "static/uploads"
|
||||||
|
os.makedirs(UPLOAD_FOLDER, exist_ok=True)
|
||||||
|
|
||||||
COUNTRIES = [
|
COUNTRIES = [
|
||||||
"Afghanistan","Albania","Algeria","Andorra","Angola","Antigua and Barbuda","Argentina","Armenia","Australia","Austria",
|
"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_DATABASE_URI'] = 'mysql+pymysql://love:love@localhost:3309/lovedb'
|
||||||
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
|
||||||
app.config['SECRET_KEY'] = 'random'
|
app.config['SECRET_KEY'] = 'random'
|
||||||
|
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
|
||||||
|
|
||||||
db = SQLAlchemy(app)
|
db = SQLAlchemy(app)
|
||||||
gpg = gnupg.GPG()
|
gpg = gnupg.GPG()
|
||||||
|
|
@ -82,7 +89,6 @@ def register():
|
||||||
lastname = request.form.get("lastname")
|
lastname = request.form.get("lastname")
|
||||||
sex = request.form.get("sex")
|
sex = request.form.get("sex")
|
||||||
date_of_birth = request.form.get("date_of_birth")
|
date_of_birth = request.form.get("date_of_birth")
|
||||||
profile_picture = request.form.get("profile_picture")
|
|
||||||
country = request.form.get("country")
|
country = request.form.get("country")
|
||||||
xmpp = request.form.get("xmpp")
|
xmpp = request.form.get("xmpp")
|
||||||
|
|
||||||
|
|
@ -94,7 +100,7 @@ def register():
|
||||||
race = request.form.get("race")
|
race = request.form.get("race")
|
||||||
prefered_age_range = request.form.get("prefered_age_range")
|
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.")
|
flash("Please fill all required fields.")
|
||||||
return redirect(url_for("register"))
|
return redirect(url_for("register"))
|
||||||
|
|
||||||
|
|
@ -126,6 +132,30 @@ def register():
|
||||||
flash("You must be at least 18 years old to register.")
|
flash("You must be at least 18 years old to register.")
|
||||||
return redirect(url_for("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"] = {
|
session["pending_user"] = {
|
||||||
"username": username,
|
"username": username,
|
||||||
"pgp": pgp,
|
"pgp": pgp,
|
||||||
|
|
@ -133,7 +163,8 @@ def register():
|
||||||
"lastname": lastname,
|
"lastname": lastname,
|
||||||
"sex": sex,
|
"sex": sex,
|
||||||
"date_of_birth": date_of_birth,
|
"date_of_birth": date_of_birth,
|
||||||
"profile_picture": profile_picture,
|
"profile_url": profile_url,
|
||||||
|
"pictures_urls": pictures_urls,
|
||||||
"country": country,
|
"country": country,
|
||||||
"xmpp": xmpp,
|
"xmpp": xmpp,
|
||||||
"email": email,
|
"email": email,
|
||||||
|
|
@ -151,10 +182,8 @@ def register():
|
||||||
return redirect(url_for("register"))
|
return redirect(url_for("register"))
|
||||||
|
|
||||||
fingerprint = import_result.fingerprints[0]
|
fingerprint = import_result.fingerprints[0]
|
||||||
|
|
||||||
random_string = secrets.token_hex(16)
|
random_string = secrets.token_hex(16)
|
||||||
challenge_phrase = f"this is the unencrypted string: {random_string}"
|
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:
|
if not encrypted_data.ok:
|
||||||
flash("Failed to encrypt challenge.")
|
flash("Failed to encrypt challenge.")
|
||||||
|
|
@ -189,7 +218,8 @@ def verify():
|
||||||
lastname=data["lastname"],
|
lastname=data["lastname"],
|
||||||
sex=data["sex"],
|
sex=data["sex"],
|
||||||
date_of_birth=dob,
|
date_of_birth=dob,
|
||||||
profile_picture=data["profile_picture"],
|
profile_picture=data["profile_url"],
|
||||||
|
pictures=data["pictures_urls"],
|
||||||
country=data["country"],
|
country=data["country"],
|
||||||
xmpp=data["xmpp"],
|
xmpp=data["xmpp"],
|
||||||
email=data["email"] or None,
|
email=data["email"] or None,
|
||||||
|
|
@ -208,6 +238,7 @@ def verify():
|
||||||
session['user_id'] = new_user.id
|
session['user_id'] = new_user.id
|
||||||
session['username'] = new_user.username
|
session['username'] = new_user.username
|
||||||
|
|
||||||
|
# limpar dados temporários
|
||||||
session.pop("pending_user", None)
|
session.pop("pending_user", None)
|
||||||
session.pop("pgp_expected_phrase", None)
|
session.pop("pgp_expected_phrase", None)
|
||||||
|
|
||||||
|
|
|
||||||
BIN
src/static/uploads/bacalhau/DSCF6156.JPG
Normal file
BIN
src/static/uploads/bacalhau/DSCF6156.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.8 MiB |
BIN
src/static/uploads/bacalhau/DSCF6158.JPG
Normal file
BIN
src/static/uploads/bacalhau/DSCF6158.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.3 MiB |
BIN
src/static/uploads/bacalhau/DSCF6162.JPG
Normal file
BIN
src/static/uploads/bacalhau/DSCF6162.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.9 MiB |
BIN
src/static/uploads/bacalhau/DSCF6168.JPG
Normal file
BIN
src/static/uploads/bacalhau/DSCF6168.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.1 MiB |
BIN
src/static/uploads/bacalhau/DSCF6170.JPG
Normal file
BIN
src/static/uploads/bacalhau/DSCF6170.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 5.2 MiB |
BIN
src/static/uploads/bacalhau/DSCF6242.JPG
Normal file
BIN
src/static/uploads/bacalhau/DSCF6242.JPG
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.2 MiB |
|
|
@ -3,48 +3,48 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h2>Register</h2>
|
<h2>Register</h2>
|
||||||
|
|
||||||
<form method="POST">
|
<form method="POST" enctype="multipart/form-data">
|
||||||
|
|
||||||
<h3>Identity</h3>
|
<h3>Identity (required)</h3>
|
||||||
<input type="text" name="username" placeholder="Username" required>*<br>
|
<input type="text" name="username" placeholder="Username" required><br>
|
||||||
<textarea name="pgp" placeholder="PGP Public Key" required></textarea>*<br>
|
<textarea name="pgp" placeholder="PGP Public Key" required></textarea><br>
|
||||||
|
|
||||||
<h3>Personal Info</h3>
|
<h3>Personal Info (required)</h3>
|
||||||
<input type="text" name="firstname" placeholder="First Name" required>*<br>
|
<input type="text" name="firstname" placeholder="First Name" required><br>
|
||||||
<input type="text" name="lastname" placeholder="Last Name" required>*<br>
|
<input type="text" name="lastname" placeholder="Last Name" required><br>
|
||||||
|
|
||||||
<select name="sex" required>
|
<select name="sex" required>
|
||||||
<option value="">Select Sex</option>
|
<option value="">Select Sex</option>
|
||||||
<option value="male">Male</option>
|
<option value="male">Male</option>
|
||||||
<option value="female">Female</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>
|
<h3>Profile Picture (required)</h3>
|
||||||
<input type="file" name="profile_picture" accept="image/*" required>*<br>
|
<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>
|
<input type="file" name="pictures" accept="image/*" multiple><br>
|
||||||
|
|
||||||
<h3>Location</h3>
|
<h3>Location (required)</h3>
|
||||||
<select name="country" required>
|
<select name="country" required>
|
||||||
<option value="">Select Country</option>
|
<option value="">Select Country</option>
|
||||||
{% for c in countries %}
|
{% for c in countries %}
|
||||||
<option value="{{ c }}">{{ c }}</option>
|
<option value="{{ c }}">{{ c }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>*<br>
|
</select><br>
|
||||||
<input type="text" name="city" placeholder="City"><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" step="0.01" name="height" placeholder="Height (m)"><br>
|
||||||
<input type="number" name="weight" placeholder="Weight (kg)"><br>
|
<input type="number" name="weight" placeholder="Weight (kg)"><br>
|
||||||
<input type="text" name="race" placeholder="Race"><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>
|
<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="text" name="xmpp" placeholder="XMPP" required><br>
|
||||||
<input type="email" name="email" placeholder="Email"><br>
|
<input type="email" name="email" placeholder="Email"><br>
|
||||||
<input type="text" name="phone" placeholder="Phone"><br><br>
|
<input type="text" name="phone" placeholder="Phone"><br><br>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue