From b569f84231ff7263c4ad76342462a471d9811c18 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Mon, 8 Jul 2024 13:03:12 +0200 Subject: [PATCH] =?UTF-8?q?A=C3=B1ado=20foto=20de=20perfil?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LyricsPy/servicios/instance/songs.db | Bin 77824 -> 77824 bytes LyricsPy/servicios/lyrics/auth.py | 27 +++++++++--- LyricsPy/servicios/lyrics/models.py | 2 + .../servicios/lyrics/templates/_cabecera.html | 5 ++- .../servicios/lyrics/templates/login.html | 8 ++-- .../servicios/lyrics/templates/signup.html | 39 ++++++++++++------ .../reymotapy/templates/_cabecera.html | 2 +- 7 files changed, 59 insertions(+), 24 deletions(-) diff --git a/LyricsPy/servicios/instance/songs.db b/LyricsPy/servicios/instance/songs.db index f516d434cf4b82e98e0ffda31848678aa4d6cdc2..8aa765260cf1fccfc702f995e7b88ea14dc2ef8e 100644 GIT binary patch delta 110 zcmZp8z|!!5WrDPzJp%)SFc8B4$3z`tQF{ixa4%l|00tJGB@Dd9e5O20_|I=_G~nTC z^kHTf7Zqh}s-Ap~r$(+IBflhHp(M4UL?JI9h)Z*F6jD;t5=(PR6qJ;jJ$Sc!@G|aD F0svKh9D4u& delta 80 zcmZp8z|!!5WrDPz4Fdy%Fc8B4>qH%6Q5y!ma4%l|00tJGBMiL7e5O1{_|I=v6bRtq cYSdw77Z(*}Y_gubj;E&Ci+8&hFXJ{P0Ct-ZBme*a diff --git a/LyricsPy/servicios/lyrics/auth.py b/LyricsPy/servicios/lyrics/auth.py index c586d5f..e24dbbb 100644 --- a/LyricsPy/servicios/lyrics/auth.py +++ b/LyricsPy/servicios/lyrics/auth.py @@ -1,7 +1,10 @@ -from flask import Blueprint, render_template, redirect, url_for, request, flash +from flask import Blueprint, render_template, redirect, url_for, request, flash, current_app 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__) @@ -36,17 +39,31 @@ def signup(): @bp.route('/signup', methods=['POST']) def signup_post(): - username = request.form.get('username') - password = request.form.get('password') + username = request.form['username'] + password = request.form['password'] + confirm_password = request.form['confirm_password'] + photo = request.files['fotoperfil'] + + 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 if user: # if a user is found, we want to redirect back to signup page so user can try again - flash('La dirección de correo ya existe') + flash('Ese usuario 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(current_app.config['UPLOAD_FOLDER'], photo_filename)) + else: + print("No hay foto") + photo_filename = "" # 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(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) diff --git a/LyricsPy/servicios/lyrics/models.py b/LyricsPy/servicios/lyrics/models.py index 5c87631..423704f 100644 --- a/LyricsPy/servicios/lyrics/models.py +++ b/LyricsPy/servicios/lyrics/models.py @@ -7,6 +7,8 @@ class User(UserMixin, db.Model): id = db.Column(db.Integer, primary_key=True) 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=False) + class Album(db.Model): id = db.Column(db.Integer, primary_key=True) diff --git a/LyricsPy/servicios/lyrics/templates/_cabecera.html b/LyricsPy/servicios/lyrics/templates/_cabecera.html index b869510..90444ce 100644 --- a/LyricsPy/servicios/lyrics/templates/_cabecera.html +++ b/LyricsPy/servicios/lyrics/templates/_cabecera.html @@ -10,16 +10,17 @@ +
@@ -55,10 +55,12 @@
+
diff --git a/LyricsPy/servicios/lyrics/templates/signup.html b/LyricsPy/servicios/lyrics/templates/signup.html index 0a0cc5f..83f6da7 100644 --- a/LyricsPy/servicios/lyrics/templates/signup.html +++ b/LyricsPy/servicios/lyrics/templates/signup.html @@ -12,7 +12,7 @@ {% with messages = get_flashed_messages() %} {% if messages %} -
+
{{ messages[0] }}. Go to login page.
{% endif %} @@ -20,7 +20,7 @@ -
Already have an account? Log in
+
¿Ya tienes una cuenta? Entra
@@ -65,10 +76,12 @@
+
diff --git a/ReymotaPy/servicios/reymotapy/templates/_cabecera.html b/ReymotaPy/servicios/reymotapy/templates/_cabecera.html index e8ba45d..960e646 100644 --- a/ReymotaPy/servicios/reymotapy/templates/_cabecera.html +++ b/ReymotaPy/servicios/reymotapy/templates/_cabecera.html @@ -119,7 +119,7 @@