Browse Source

Añado foto de perfil

politica
Celestino Rey 1 year ago
parent
commit
b569f84231
7 changed files with 59 additions and 24 deletions
  1. BIN
      LyricsPy/servicios/instance/songs.db
  2. +22
    -5
      LyricsPy/servicios/lyrics/auth.py
  3. +2
    -0
      LyricsPy/servicios/lyrics/models.py
  4. +3
    -2
      LyricsPy/servicios/lyrics/templates/_cabecera.html
  5. +5
    -3
      LyricsPy/servicios/lyrics/templates/login.html
  6. +26
    -13
      LyricsPy/servicios/lyrics/templates/signup.html
  7. +1
    -1
      ReymotaPy/servicios/reymotapy/templates/_cabecera.html

BIN
LyricsPy/servicios/instance/songs.db View File


+ 22
- 5
LyricsPy/servicios/lyrics/auth.py View File

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


+ 2
- 0
LyricsPy/servicios/lyrics/models.py View File

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


+ 3
- 2
LyricsPy/servicios/lyrics/templates/_cabecera.html View File

@ -10,16 +10,17 @@
</a>
</div><!--//col-->
<div class="app-utilities col-auto">
<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('static', filename=current_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><hr class="dropdown-divider"></li>
<li><a class="dropdown-item" href="{{ url_for('auth.logout') }}">Log Out</a></li>
{% else %}


+ 5
- 3
LyricsPy/servicios/lyrics/templates/login.html View File

@ -10,7 +10,7 @@
<div class="auth-form-container text-start">
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="notification is-danger">
<div class="app-card alert alert-dismissible shadow-sm mb-4 border-left-decoration"">
{{ messages[0] }}
</div>
{% endif %}
@ -28,7 +28,7 @@
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="RememberPassword">
<label class="form-check-label" for="RememberPassword">
Remember me
Recuérdame
</label>
</div>
</div><!--//col-6-->
@ -39,7 +39,7 @@
</div>
</form>
<div class="auth-option text-center pt-5">No Account? Sign up <a class="text-link" href="{{ url_for('auth.signup') }}" >here</a>.</div>
<div class="auth-option text-center pt-5">¿No tienes cuenta? Registrate <a class="text-link" href="{{ url_for('auth.signup') }}" >aquí</a>.</div>
</div><!--//auth-form-container-->
</div><!--//auth-body-->
@ -55,10 +55,12 @@
<div class="auth-background-overlay p-3 p-lg-5">
<div class="d-flex flex-column align-content-end h-100">
<div class="h-100"></div>
<!--
<div class="overlay-content p-3 p-lg-4 rounded">
<h5 class="mb-3 overlay-title">Explore Portal Admin Template</h5>
<div>Portal is a free Bootstrap 5 admin dashboard template. You can download and view the template license <a href="https://themes.3rdwavemedia.com/bootstrap-templates/admin-dashboard/portal-free-bootstrap-admin-dashboard-template-for-developers/">here</a>.</div>
</div>
-->
</div>
</div><!--//auth-background-overlay-->
</div><!--//auth-background-col-->


+ 26
- 13
LyricsPy/servicios/lyrics/templates/signup.html View File

@ -12,7 +12,7 @@
{% with messages = get_flashed_messages() %}
{% if messages %}
<div class="notification is-danger">
<div class="app-card alert alert-dismissible shadow-sm mb-4 border-left-decoration">
{{ messages[0] }}. Go to <a href="{{ url_for('auth.login') }}">login page</a>.
</div>
{% endif %}
@ -20,7 +20,7 @@
<form class="auth-form auth-signup-form" method="POST" action="/signup">
<div class="email mb-3">
<label class="sr-only" for="signup-name">Your Name</label>
<label class="sr-only" for="signup-name">Usuario</label>
<input id="signup-name" name="username" type="text" class="form-control signup-name" placeholder="Nombre de usuario" required="required">
</div>
<!--
@ -31,23 +31,34 @@
-->
<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">
<input id="signup-password" name="password" type="password" class="form-control signup-password" placeholder="Crea una password" required="required">
</div>
<div class="extra mb-3">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="RememberPassword">
<label class="form-check-label" for="RememberPassword">
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 class="password mb-3">
<label class="sr-only" for="confirm_password">Confirma 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="fotoperfil">Foto de perfil:</label>
<input id="fotoperfil"
name="fotoperfil"
type="file"
class="form-control"
required="required">
</div>
<div class="text-center">
<button type="submit" class="btn app-btn-primary w-100 theme-btn mx-auto">Sign Up</button>
</div>
</form><!--//auth-form-->
<div class="auth-option text-center pt-5">Already have an account? <a class="text-link" href="{{ url_for('auth.login') }}" >Log in</a></div>
<div class="auth-option text-center pt-5">¿Ya tienes una cuenta? <a class="text-link" href="{{ url_for('auth.login') }}" >Entra</a></div>
</div><!--//auth-form-container-->
@ -65,10 +76,12 @@
<div class="auth-background-overlay p-3 p-lg-5">
<div class="d-flex flex-column align-content-end h-100">
<div class="h-100"></div>
<!--
<div class="overlay-content p-3 p-lg-4 rounded">
<h5 class="mb-3 overlay-title">Explore Portal Admin Template</h5>
<div>Portal is a free Bootstrap 5 admin dashboard template. You can download and view the template license <a href="https://themes.3rdwavemedia.com/bootstrap-templates/admin-dashboard/portal-free-bootstrap-admin-dashboard-template-for-developers/">here</a>.</div>
</div>
-->
</div>
</div><!--//auth-background-overlay-->
</div><!--//auth-background-col-->


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

@ -119,7 +119,7 @@
</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('paginas.uploaded_file', filename=current_user.photo) }}" 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=current_user.photo) }}" alt="{{ current_user.username }}"></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 %}


Loading…
Cancel
Save