From f9db7be7bf2fab11a4f793f169596919329e5fba Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Mon, 8 Jul 2024 10:15:10 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1ado=20campo=20foto=20de=20perfil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ReymotaPy/servicios/instance/reymotapy.db | Bin 12288 -> 12288 bytes ReymotaPy/servicios/requirements.txt | 2 +- ReymotaPy/servicios/reymotapy/__init__.py | 3 ++ ReymotaPy/servicios/reymotapy/auth.py | 33 +++++++++++++++--- ReymotaPy/servicios/reymotapy/models.py | 2 ++ .../reymotapy/templates/_cabecera.html | 4 +-- .../servicios/reymotapy/templates/signup.html | 20 ++++++++--- 7 files changed, 52 insertions(+), 12 deletions(-) diff --git a/ReymotaPy/servicios/instance/reymotapy.db b/ReymotaPy/servicios/instance/reymotapy.db index abd5173b0c5d0dec38c53dd52bdcd026f97a161a..2608bf3338cf28ccb55498ec35a1103447d3564f 100644 GIT binary patch delta 371 zcmZojXh@hKEy&Hlz`zW|Fu*)f#~3K6m$!?T{|5sT-vb7|2mI$Z78dYvHs&z0i;Idf zHc!^%ueD3fP0Y+uC`qj-QOL^&;?kTPg_P8^#L}D+1tldNg@TOyl6;);FgET`6!(?M)ptOmZWm=+P8jzQ0 zW@cobotc-emy}wRmspgdm*kKR@`7G+er^FXD}#7rWMWEgW?n&3c1oI&RdGh*vUx9&Nf&ctwL4^%`oQ*n+?Bb%L zj7^hY^3_gW#vjcK)WyuVl!3pCUz~3#P|%g@PY;$fEOOfE{T%*iiEtpWfG13p>+ diff --git a/ReymotaPy/servicios/requirements.txt b/ReymotaPy/servicios/requirements.txt index 99749ea..60d258e 100644 --- a/ReymotaPy/servicios/requirements.txt +++ b/ReymotaPy/servicios/requirements.txt @@ -11,4 +11,4 @@ MarkupSafe==2.1.5 packaging==24.1 SQLAlchemy==2.0.31 typing_extensions==4.12.2 -Werkzeug==3.0.3 +Werkzeug==3.0.3 \ No newline at end of file diff --git a/ReymotaPy/servicios/reymotapy/__init__.py b/ReymotaPy/servicios/reymotapy/__init__.py index 3e9a63c..de7173a 100644 --- a/ReymotaPy/servicios/reymotapy/__init__.py +++ b/ReymotaPy/servicios/reymotapy/__init__.py @@ -18,6 +18,9 @@ def create_app(): app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB máximo + # Asegúrate de que el directorio de carga existe + os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True) + from .models import db db.init_app(app) diff --git a/ReymotaPy/servicios/reymotapy/auth.py b/ReymotaPy/servicios/reymotapy/auth.py index 6ee317f..7304b12 100644 --- a/ReymotaPy/servicios/reymotapy/auth.py +++ b/ReymotaPy/servicios/reymotapy/auth.py @@ -1,7 +1,10 @@ from flask import Blueprint, render_template, redirect, url_for, request, flash from werkzeug.security import generate_password_hash, check_password_hash +from werkzeug.utils import secure_filename from flask_login import login_user, logout_user, login_required from .models import User +import os + from . import db bp = Blueprint('auth', __name__) @@ -39,8 +42,15 @@ def signup(): @bp.route('/signup', methods=['POST']) def signup_post(): print("Creando usuario") + email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') + confirm_password = request.form.get('confirm_password') + photo = request.files['photo'] + + if password != confirm_password: + flash('Passwords do not match.') + return redirect(url_for('auth.signup')) user = User.query.filter_by(username=username).first() # if this returns a user, then the user already exists in database @@ -48,14 +58,27 @@ def signup_post(): flash('La dirección de correo ya existe') return redirect(url_for('auth.signup')) + + if photo: + photo_filename = secure_filename(photo.filename) + print("Foto: ", photo_filename) + photo.save(os.path.join(bp.config['UPLOAD_FOLDER'], photo_filename)) + else: + photo_filename = None + # create a new user with the form data. Hash the password so the plaintext version isn't saved. - new_user = User(username=username, password=generate_password_hash(password, method='pbkdf2:sha256')) + new_user = User(email=email, username=username, password=generate_password_hash(password, method='pbkdf2:sha256'), photo=photo_filename) # add the new user to the database - db.session.add(new_user) - db.session.commit() - - return redirect(url_for('auth.login')) + try: + db.session.add(new_user) + db.session.commit() + flash('Registration successful.') + return redirect(url_for('auth.login')) + except: + flash('Email address already exists.') + return redirect(url_for('auth.login')) + @bp.route('/logout') @login_required diff --git a/ReymotaPy/servicios/reymotapy/models.py b/ReymotaPy/servicios/reymotapy/models.py index 9e66828..c73438d 100644 --- a/ReymotaPy/servicios/reymotapy/models.py +++ b/ReymotaPy/servicios/reymotapy/models.py @@ -5,6 +5,8 @@ from . import db class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) + email = db.Column(db.String(150), unique=True, nullable=False) username = db.Column(db.String(150), unique=True, nullable=False) password = db.Column(db.String(150), nullable=False) + photo = db.Column(db.String(150), nullable=True) diff --git a/ReymotaPy/servicios/reymotapy/templates/_cabecera.html b/ReymotaPy/servicios/reymotapy/templates/_cabecera.html index 3f6c864..e75ad2a 100644 --- a/ReymotaPy/servicios/reymotapy/templates/_cabecera.html +++ b/ReymotaPy/servicios/reymotapy/templates/_cabecera.html @@ -119,13 +119,13 @@ - +
+ +
+ + +
+ +
+ + +
+ + + //extra-->