diff --git a/LyricsPy/servicios/instance/songs.db b/LyricsPy/servicios/instance/songs.db index f516d43..8aa7652 100644 Binary files a/LyricsPy/servicios/instance/songs.db and b/LyricsPy/servicios/instance/songs.db differ 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 %} -