From 4f3eeb549fdaf021eb98e488ebd1d8ab427eb877 Mon Sep 17 00:00:00 2001 From: Celestino Rey Date: Thu, 11 Jul 2024 10:47:15 +0200 Subject: [PATCH] signup funcionando bien --- LyricsPy/K8S/Makefile | 2 +- LyricsPy/servicios/lyrics/auth.py | 16 +++++++++++----- LyricsPy/servicios/lyrics/templates/signup.html | 12 ++++++++---- RecetasPy/servicios/recetaspy/auth.py | 13 +++++++++++-- .../servicios/recetaspy/templates/login.html | 2 +- .../servicios/recetaspy/templates/signup.html | 14 +++++++++----- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/LyricsPy/K8S/Makefile b/LyricsPy/K8S/Makefile index aba6cd3..e27b90c 100644 --- a/LyricsPy/K8S/Makefile +++ b/LyricsPy/K8S/Makefile @@ -1,4 +1,4 @@ -export IMG_VERSION = 6.4 +export IMG_VERSION = 6.5 imagen: cd ../servicios; make diff --git a/LyricsPy/servicios/lyrics/auth.py b/LyricsPy/servicios/lyrics/auth.py index e24dbbb..10c40e3 100644 --- a/LyricsPy/servicios/lyrics/auth.py +++ b/LyricsPy/servicios/lyrics/auth.py @@ -39,10 +39,15 @@ def signup(): @bp.route('/signup', methods=['POST']) def signup_post(): - username = request.form['username'] - password = request.form['password'] - confirm_password = request.form['confirm_password'] - photo = request.files['fotoperfil'] + if 'photo' not in request.files: + flash('No file part') + return redirect(request.url) + + username = request.form.get('username') +# email = request.form.get('email') + 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.') @@ -71,8 +76,9 @@ def signup_post(): return redirect(url_for('auth.login')) + @bp.route('/logout') @login_required def logout(): logout_user() - return redirect(url_for('paginas.index')) + return redirect(url_for('paginas.index')) \ No newline at end of file diff --git a/LyricsPy/servicios/lyrics/templates/signup.html b/LyricsPy/servicios/lyrics/templates/signup.html index add680a..0bce258 100644 --- a/LyricsPy/servicios/lyrics/templates/signup.html +++ b/LyricsPy/servicios/lyrics/templates/signup.html @@ -18,17 +18,17 @@ {% endif %} {% endwith %} -
+ - +-->
@@ -43,7 +43,7 @@ placeholder="Confirm password" required="required">
- + +
+ +
diff --git a/RecetasPy/servicios/recetaspy/auth.py b/RecetasPy/servicios/recetaspy/auth.py index 03fa8af..a58fd92 100644 --- a/RecetasPy/servicios/recetaspy/auth.py +++ b/RecetasPy/servicios/recetaspy/auth.py @@ -40,9 +40,12 @@ def signup(): @bp.route('/signup', methods=['POST']) def signup_post(): username = request.form.get('username') + email = request.form.get('email') password = request.form.get('password') confirm_password = request.form.get('confirm_password') - photo = request.files['fotoperfil'] +# photo = request.files['fotoperfil'] + + photo = request.files['photo'] if password != confirm_password: flash('Passwords do not match.') @@ -53,6 +56,12 @@ def signup_post(): if user: # if a user is found, we want to redirect back to signup page so user can try again flash('Ese usuario ya existe') return redirect(url_for('auth.signup')) + + correo = User.query.filter_by(email=email).first() # if this returns a user, then the user already exists in database + + if correo: # if a user is found, we want to redirect back to signup page so user can try again + flash('Ese correo ya existe') + return redirect(url_for('auth.signup')) if photo: photo_filename = secure_filename(photo.filename) @@ -63,7 +72,7 @@ def signup_post(): 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'), photo=photo_filename) + 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) diff --git a/RecetasPy/servicios/recetaspy/templates/login.html b/RecetasPy/servicios/recetaspy/templates/login.html index c41db02..b57fe4b 100644 --- a/RecetasPy/servicios/recetaspy/templates/login.html +++ b/RecetasPy/servicios/recetaspy/templates/login.html @@ -15,7 +15,7 @@
{% endif %} {% endwith %} - +
diff --git a/RecetasPy/servicios/recetaspy/templates/signup.html b/RecetasPy/servicios/recetaspy/templates/signup.html index 12c28d4..096de5b 100644 --- a/RecetasPy/servicios/recetaspy/templates/signup.html +++ b/RecetasPy/servicios/recetaspy/templates/signup.html @@ -18,17 +18,17 @@ {% endif %} {% endwith %} - + - +
@@ -43,7 +43,7 @@ placeholder="Confirm password" required="required">
- + +
+ +
+