Browse Source

Añado campo foto de perfil

politica
Celestino Rey 1 year ago
parent
commit
f9db7be7bf
7 changed files with 52 additions and 12 deletions
  1. BIN
      ReymotaPy/servicios/instance/reymotapy.db
  2. +1
    -1
      ReymotaPy/servicios/requirements.txt
  3. +3
    -0
      ReymotaPy/servicios/reymotapy/__init__.py
  4. +28
    -5
      ReymotaPy/servicios/reymotapy/auth.py
  5. +2
    -0
      ReymotaPy/servicios/reymotapy/models.py
  6. +2
    -2
      ReymotaPy/servicios/reymotapy/templates/_cabecera.html
  7. +16
    -4
      ReymotaPy/servicios/reymotapy/templates/signup.html

BIN
ReymotaPy/servicios/instance/reymotapy.db View File


+ 1
- 1
ReymotaPy/servicios/requirements.txt View File

@ -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

+ 3
- 0
ReymotaPy/servicios/reymotapy/__init__.py View File

@ -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)


+ 28
- 5
ReymotaPy/servicios/reymotapy/auth.py View File

@ -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


+ 2
- 0
ReymotaPy/servicios/reymotapy/models.py View File

@ -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)

+ 2
- 2
ReymotaPy/servicios/reymotapy/templates/_cabecera.html View File

@ -119,13 +119,13 @@
</div><!--//app-utility-item-->
<div class="app-utility-item app-user-dropdown dropdown">
{% if current_user.is_authenticated %}
<a class="dropdown-toggle" id="user-dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false"><img src="{{ url_for('static', filename='images/user.png') }}" alt="user profile"></a>
<a class="dropdown-toggle" id="user-dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false"><img src="{{ url_for('paginas.uploaded_file', filename=user.photo) }}" alt="user profile"></a>
{% else %}
<a class="dropdown-toggle" id="user-dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false"><img src="{{ url_for('static', filename='images/reymota-logo.svg') }}" alt="user profile"></a>
{% endif %}
<ul class="dropdown-menu" aria-labelledby="user-dropdown-toggle">
{% if current_user.is_authenticated %}
<li><a class="dropdown-item" href="{{ url_for('paginas.account') }}">Account</a></li>
<li><a class="dropdown-item" href="{{ url_for('paginas.account') }}">Account {{ current_user.username }} </a></li>
<li><a class="dropdown-item" href="{{ url_for('paginas.settings') }}">Settings</a></li>
<li><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">Log Out</a></li>


+ 16
- 4
ReymotaPy/servicios/reymotapy/templates/signup.html View File

@ -23,16 +23,28 @@
<label class="sr-only" for="signup-name">Your Name</label>
<input id="signup-name" name="username" type="text" class="form-control signup-name" placeholder="Nombre de usuario" required="required">
</div>
<!--
<div class="email mb-3">
<label class="sr-only" for="email">Your Email</label>
<input id="signup-email" name="email" type="email" class="form-control signup-email" placeholder="Email" required="required">
<input id="signup-email" name="email" type="email" class="form-control signup-email" placeholder="Email" required="required">
</div>
-->
<div class="password mb-3">
<label class="sr-only" for="password">Password</label>
<input id="signup-password" name="password" type="password" class="form-control signup-password" placeholder="Create a password" required="required">
</div>
<div class="password mb-3">
<label class="sr-only" for="confirm_password">Confirm password</label>
<input id="confirm_password" name="confirm_password" type="password" class="form-control signup-password" placeholder="Confirm password" required="required">
</div>
<div class="text mb-3">
<label for="photo">Foto de perfil:</label>
<input class="form-control" name="photo" type="file" id="photo">
</div>
<!--
<div class="extra mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="RememberPassword">
@ -40,7 +52,7 @@
I agree to Portal's <a href="#" class="app-link">Terms of Service</a> and <a href="#" class="app-link">Privacy Policy</a>.
</label>
</div>
</div><!--//extra-->
</div>//extra-->
<div class="text-center">
<button type="submit" class="btn app-btn-primary w-100 theme-btn mx-auto">Sign Up</button>


Loading…
Cancel
Save