Browse Source

Con registro de usuario y login necesario para añadir letras y álbumes

politica
Celestino Rey 1 year ago
parent
commit
e721d12d8d
11 changed files with 19 additions and 74 deletions
  1. +1
    -1
      LyricsPy/K8S/lyrics-deployment.yaml
  2. +2
    -2
      LyricsPy/servicios/creaImagen.sh
  3. BIN
      LyricsPy/servicios/instance/songs.db
  4. +7
    -8
      LyricsPy/servicios/lyrics/auth.py
  5. +1
    -1
      LyricsPy/servicios/lyrics/models.py
  6. +0
    -9
      LyricsPy/servicios/lyrics/paginas.py
  7. +4
    -1
      LyricsPy/servicios/lyrics/templates/_navegacion.html
  8. +1
    -11
      LyricsPy/servicios/lyrics/templates/base.html
  9. +1
    -1
      LyricsPy/servicios/lyrics/templates/login.html
  10. +0
    -32
      LyricsPy/servicios/lyrics/templates/search.html
  11. +2
    -8
      LyricsPy/servicios/lyrics/templates/signup.html

+ 1
- 1
LyricsPy/K8S/lyrics-deployment.yaml View File

@ -36,7 +36,7 @@ spec:
- --bind
- 0.0.0.0:5000
- lyrics:create_app()
image: creylopez/lyrics:4.0
image: creylopez/lyrics:5.0
name: lyrics
ports:
- containerPort: 5000


+ 2
- 2
LyricsPy/servicios/creaImagen.sh View File

@ -1,3 +1,3 @@
docker build --no-cache -t creylopez/lyrics:4.0 .
docker push creylopez/lyrics:4.0
docker build --no-cache -t creylopez/lyrics:5.0 .
docker push creylopez/lyrics:5.0

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


+ 7
- 8
LyricsPy/servicios/lyrics/auth.py View File

@ -13,11 +13,11 @@ def login():
@bp.route('/login', methods=['POST'])
def login_post():
email = request.form.get('email')
username = request.form.get('username')
password = request.form.get('password')
remember = True if request.form.get('remember') else False
user = User.query.filter_by(email=email).first()
user = User.query.filter_by(username=username).first()
# check if the user actually exists
# take the user-supplied password, hash it, and compare it to the hashed password in the database
@ -28,7 +28,7 @@ def login_post():
# if the above check passes, then we know the user has the right credentials
login_user(user, remember=remember)
return redirect(url_for('reservas.misreservas'))
return redirect(url_for('paginas.index'))
@bp.route('/signup')
def signup():
@ -36,18 +36,17 @@ def signup():
@bp.route('/signup', methods=['POST'])
def signup_post():
email = request.form.get('email')
name = request.form.get('name')
username = request.form.get('username')
password = request.form.get('password')
user = User.query.filter_by(email=email).first() # if this returns a user, then the email already exists in database
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')
return redirect(url_for('auth.signup'))
# create a new user with the form data. Hash the password so the plaintext version isn't saved.
new_user = User(email=email, name=name, password=generate_password_hash(password, method='pbkdf2:sha256'))
new_user = User(username=username, password=generate_password_hash(password, method='pbkdf2:sha256'))
# add the new user to the database
db.session.add(new_user)
@ -59,4 +58,4 @@ def signup_post():
@login_required
def logout():
logout_user()
return redirect(url_for('auth.index'))
return redirect(url_for('paginas.index'))

+ 1
- 1
LyricsPy/servicios/lyrics/models.py View File

@ -1,7 +1,7 @@
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
db = SQLAlchemy()
from . import db
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)


+ 0
- 9
LyricsPy/servicios/lyrics/paginas.py View File

@ -79,15 +79,6 @@ def album(album_id):
songs = Song.query.filter_by(album_id=album_id).all()
return render_template('album.html', album=album, songs=songs)
@bp.route('/search')
def search():
query = request.args.get('query', '')
if query:
songs = Song.query.filter(Song.title.contains(query)).all()
else:
songs = []
return render_template('search.html', query=query, songs=songs)
@bp.route('/uploads/<filename>')
@login_required
def uploaded_file(filename):


+ 4
- 1
LyricsPy/servicios/lyrics/templates/_navegacion.html View File

@ -23,13 +23,16 @@
<div class="navbar-item">
<!-- <div class="buttons">-->
{% if current_user.is_authenticated %}
<a class="navbar-item" href="{{ url_for('paginas.add_song') }}">Añadir canción</a>
<a class="navbar-item" href="{{ url_for('paginas.add_album') }}">Añadir álbum</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
{{ current_user.name }}
</a>
<div class="navbar-dropdown">
<a href="{{ url_for('reservas.misreservas') }}" class="navbar-item">Mis reservas</a>
<a href="{{ url_for('paginas.index') }}" class="navbar-item">Mis reservas</a>
<a href="{{ url_for('auth.logout') }}" class="navbar-item">Salir</a>
</div>


+ 1
- 11
LyricsPy/servicios/lyrics/templates/base.html View File

@ -28,17 +28,7 @@
</header>
<div class="container has-text-centered mt-5">
<h1>Mis letras de canciones</h1>
<nav>
<a href="{{ url_for('paginas.index') }}">Inicio</a>
<a href="{{ url_for('paginas.add_song') }}">Añadir canción</a>
<a href="{{ url_for('paginas.add_album') }}">Añadir álbum</a>
<!--
<form action="{{ url_for('paginas.search') }}" method="get" style="display:inline;">
<input type="text" name="query" placeholder="Search songs...">
<button type="submit">Search</button>
</form>
-->
</nav>
<hr>
{% block content %}{% endblock %}
</div>


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

@ -14,7 +14,7 @@
<form method="POST" action="/login">
<div class="field">
<div class="control">
<input class="input is-large" type="email" name="email" placeholder="Tu correo" autofocus="">
<input class="input is-large" type="text" name="username" placeholder="Tu correo" autofocus="">
</div>
</div>


+ 0
- 32
LyricsPy/servicios/lyrics/templates/search.html View File

@ -1,32 +0,0 @@
{% extends 'base.html' %}
{% block content %}
<h2>Resultados de la búsqueda para "{{ query }}"</h2>
{% if songs %}
<table id="songTable" class="display">
<thead>
<tr>
<th>Pista</th>
<th>Título</th>
<th>Autor</th>
<th>Álbum</th>
</tr>
</thead>
<tbody>
{% for song in songs %}
<tr>
<td>{{ song.pista }}</td>
<td><a href="{{ url_for('paginas.song', song_id=song.id) }}">{{ song.title }}</a></td>
<td>{{ song.author }}</td>
<td><a href="{{ url_for('paginas.album', album_id=song.album.id) }}">{{ song.album.name }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>No he econtrado canciones que concuerden con tu petición.</p>
{% endif %}
<a href="{{ url_for('paginas.index') }}">Volver al inicio</a>
{% endblock %}

+ 2
- 8
LyricsPy/servicios/lyrics/templates/signup.html View File

@ -14,15 +14,9 @@
{% endwith %}
<form method="POST" action="/signup">
<div class="field">
<div class="control">
<input class="input is-large" type="email" name="email" placeholder="Email" autofocus="">
</div>
</div>
<div class="field">
<div class="field">
<div class="control">
<input class="input is-large" type="text" name="name" placeholder="Nombre" autofocus="">
<input class="input is-large" type="text" name="username" placeholder="Nombre" autofocus="">
</div>
</div>


Loading…
Cancel
Save