Browse Source

Seguimos avanzando

politica
Celestino Rey 1 year ago
parent
commit
d74834f9ac
11 changed files with 17 additions and 195 deletions
  1. +0
    -107
      PruebaFoto/app.py
  2. BIN
      PruebaFoto/instance/users.db
  3. BIN
      PruebaFoto/static/uploads/daniel.jpg
  4. BIN
      PruebaFoto/static/uploads/theriver.jpg
  5. +0
    -18
      PruebaFoto/templates/index.html
  6. +0
    -17
      PruebaFoto/templates/login.html
  7. +0
    -15
      PruebaFoto/templates/profile.html
  8. +0
    -21
      PruebaFoto/templates/register.html
  9. BIN
      RecetasPy/servicios/instance/recipes.db
  10. +1
    -1
      RecetasPy/servicios/recetaspy/paginas.py
  11. +16
    -16
      RecetasPy/servicios/recetaspy/templates/recetas.html

+ 0
- 107
PruebaFoto/app.py View File

@ -1,107 +0,0 @@
import os
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_login import LoginManager, UserMixin, login_user, login_required, logout_user, current_user
from flask_sqlalchemy import SQLAlchemy
from werkzeug.security import generate_password_hash, check_password_hash
from werkzeug.utils import secure_filename
app = Flask(__name__)
app.secret_key = 'your_secret_key' # Cambia esto por una clave secreta segura
# Configuración de la base de datos
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///users.db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
# Configuración para subir archivos
app.config['UPLOAD_FOLDER'] = 'uploads'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024 # 16 MB
# Asegúrate de que el directorio de carga existe
os.makedirs(app.config['UPLOAD_FOLDER'], exist_ok=True)
# Inicializa la base de datos
db = SQLAlchemy(app)
# Inicializa Flask-Login
login_manager = LoginManager()
login_manager.init_app(app)
login_manager.login_view = 'login'
# Modelo de usuario
class User(UserMixin, db.Model):
id = db.Column(db.Integer, primary_key=True)
email = 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)
@login_manager.user_loader
def load_user(user_id):
return User.query.get(int(user_id))
@app.route('/')
def index():
return render_template('index.html')
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
user = User.query.filter_by(email=email).first()
if user and check_password_hash(user.password, password):
login_user(user)
flash('Logged in successfully.')
return redirect(url_for('profile'))
else:
flash('Invalid email or password.')
return render_template('login.html')
@app.route('/logout')
@login_required
def logout():
logout_user()
flash('Logged out successfully.')
return redirect(url_for('index'))
@app.route('/profile')
@login_required
def profile():
photo_url = url_for('static', filename='uploads/' + current_user.photo) if current_user.photo else None
return render_template('profile.html', email=current_user.email, photo_url=photo_url)
@app.route('/register', methods=['GET', 'POST'])
def register():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
confirm_password = request.form['confirm_password']
photo = request.files['photo']
if password != confirm_password:
flash('Passwords do not match.')
return redirect(url_for('register'))
hashed_password = generate_password_hash(password)
if photo:
photo_filename = secure_filename(photo.filename)
photo.save(os.path.join(app.config['UPLOAD_FOLDER'], photo_filename))
else:
photo_filename = None
new_user = User(email=email, password=hashed_password, photo=photo_filename)
try:
db.session.add(new_user)
db.session.commit()
flash('Registration successful.')
return redirect(url_for('login'))
except:
flash('Email address already exists.')
return redirect(url_for('register'))
return render_template('register.html')
if __name__ == '__main__':
with app.app_context():
db.create_all()
app.run(debug=True)

BIN
PruebaFoto/instance/users.db View File


BIN
PruebaFoto/static/uploads/daniel.jpg View File

Before After
Width: 959  |  Height: 1280  |  Size: 65 KiB

BIN
PruebaFoto/static/uploads/theriver.jpg View File

Before After
Width: 320  |  Height: 320  |  Size: 34 KiB

+ 0
- 18
PruebaFoto/templates/index.html View File

@ -1,18 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Example App</title>
</head>
<body>
<h1>Welcome to the Example App</h1>
{% if current_user.is_authenticated %}
<p>Welcome, {{ current_user.email }}!</p>
<a href="{{ url_for('profile') }}">Profile</a>
<a href="{{ url_for('logout') }}">Logout</a>
{% else %}
<a href="{{ url_for('login') }}">Login</a>
<a href="{{ url_for('register') }}">Register</a>
{% endif %}
</body>
</html>

+ 0
- 17
PruebaFoto/templates/login.html View File

@ -1,17 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Login</title>
</head>
<body>
<h1>Login</h1>
<form action="{{ url_for('login') }}" method="post">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<button type="submit">Login</button>
</form>
</body>
</html>

+ 0
- 15
PruebaFoto/templates/profile.html View File

@ -1,15 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Profile</title>
</head>
<body>
<h1>Profile</h1>
<p>Email: {{ email }}</p>
{% if photo_url %}
<img src="{{ photo_url }}" alt="Profile Photo">
{% endif %}
<a href="{{ url_for('logout') }}">Logout</a>
</body>
</html>

+ 0
- 21
PruebaFoto/templates/register.html View File

@ -1,21 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Register</title>
</head>
<body>
<h1>Register</h1>
<form action="{{ url_for('register') }}" method="post" enctype="multipart/form-data">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
<label for="confirm_password">Confirm Password:</label>
<input type="password" id="confirm_password" name="confirm_password" required>
<label for="photo">Profile Photo:</label>
<input type="file" id="photo" name="photo">
<button type="submit">Register</button>
</form>
</body>
</html>

BIN
RecetasPy/servicios/instance/recipes.db View File


+ 1
- 1
RecetasPy/servicios/recetaspy/paginas.py View File

@ -16,7 +16,7 @@ def index():
@bp.route('/recipe/<int:recipe_id>') @bp.route('/recipe/<int:recipe_id>')
def recipe(recipe_id): def recipe(recipe_id):
recipe = Recipe.query.get_or_404(recipe_id) recipe = Recipe.query.get_or_404(recipe_id)
return render_template('recipe.html', recipe=recipe)
return render_template('recetas.html', recipe=recipe)
@bp.route('/new_recipe', methods=['GET', 'POST']) @bp.route('/new_recipe', methods=['GET', 'POST'])
@login_required @login_required


+ 16
- 16
RecetasPy/servicios/recetaspy/templates/recetas.html View File

@ -11,7 +11,7 @@
<nav id="orders-table-tab" class="orders-table-tab app-nav-tabs nav shadow-sm flex-column flex-sm-row mb-4"> <nav id="orders-table-tab" class="orders-table-tab app-nav-tabs nav shadow-sm flex-column flex-sm-row mb-4">
<a class="flex-sm-fill text-sm-center nav-link active" id="letras-tab" data-bs-toggle="tab" href="#letras" role="tab" aria-controls="letras" aria-selected="true">Letras</a>
<a class="flex-sm-fill text-sm-center nav-link active" id="recetas-tab" data-bs-toggle="tab" href="#recetas" role="tab" aria-controls="recetas" aria-selected="true">Recetas</a>
<!-- <!--
<a class="flex-sm-fill text-sm-center nav-link" id="albumes-tab" data-bs-toggle="tab" href="#albumes" role="tab" aria-controls="albumes" aria-selected="false">Álbumes</a> <a class="flex-sm-fill text-sm-center nav-link" id="albumes-tab" data-bs-toggle="tab" href="#albumes" role="tab" aria-controls="albumes" aria-selected="false">Álbumes</a>
<a class="flex-sm-fill text-sm-center nav-link" id="orders-pending-tab" data-bs-toggle="tab" href="#orders-pending" role="tab" aria-controls="orders-pending" aria-selected="false">Pending</a> <a class="flex-sm-fill text-sm-center nav-link" id="orders-pending-tab" data-bs-toggle="tab" href="#orders-pending" role="tab" aria-controls="orders-pending" aria-selected="false">Pending</a>
@ -21,24 +21,24 @@
<div class="tab-content" id="orders-table-tab-content"> <div class="tab-content" id="orders-table-tab-content">
<div class="tab-pane fade show active" id="letras" role="tabpanel" aria-labelledby="letras-tab">
<div class="tab-pane fade show active" id="recetas" role="tabpanel" aria-labelledby="recetas-tab">
<div class="app-card app-card-orders-table shadow-sm mb-5"> <div class="app-card app-card-orders-table shadow-sm mb-5">
<div class="app-card-body"> <div class="app-card-body">
<div class="table-responsive"> <div class="table-responsive">
<table class="table app-table-hover mb-0 text-left">
<thead>
<tr>
<th class="cell">Receta</th>
</tr>
</thead>
<tbody>
{% for recipe in recipes %}
<tr>
<td class="cell"><a href="{{ url_for('paginas.recipe', recipe_id=recipe.id) }}">{{ recipe.title }}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
<h1>{{ recipe.title }}</h1>
<p>{{ recipe.description }}</p>
<h2>Ingredients</h2>
<ul>
{% for ingredient in recipe.ingredients %}
<li>{{ ingredient.quantity }} {{ ingredient.name }}</li>
{% endfor %}
</ul>
<h2>Instructions</h2>
<ol>
{% for instruction in recipe.instructions %}
<li>{{ instruction.description }}</li>
{% endfor %}
</ol>
</div><!--//table-responsive--> </div><!--//table-responsive-->
</div><!--//app-card-body--> </div><!--//app-card-body-->
</div><!--//app-card--> </div><!--//app-card-->


Loading…
Cancel
Save