diff --git a/PruebaFoto/app.py b/PruebaFoto/app.py deleted file mode 100644 index 17dc82e..0000000 --- a/PruebaFoto/app.py +++ /dev/null @@ -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) diff --git a/PruebaFoto/instance/users.db b/PruebaFoto/instance/users.db deleted file mode 100644 index bbacd32..0000000 Binary files a/PruebaFoto/instance/users.db and /dev/null differ diff --git a/PruebaFoto/static/uploads/daniel.jpg b/PruebaFoto/static/uploads/daniel.jpg deleted file mode 100644 index d7775bd..0000000 Binary files a/PruebaFoto/static/uploads/daniel.jpg and /dev/null differ diff --git a/PruebaFoto/static/uploads/theriver.jpg b/PruebaFoto/static/uploads/theriver.jpg deleted file mode 100644 index 3caa7cd..0000000 Binary files a/PruebaFoto/static/uploads/theriver.jpg and /dev/null differ diff --git a/PruebaFoto/templates/index.html b/PruebaFoto/templates/index.html deleted file mode 100644 index 16613ca..0000000 --- a/PruebaFoto/templates/index.html +++ /dev/null @@ -1,18 +0,0 @@ - - -
- -Welcome, {{ current_user.email }}!
- Profile - Logout - {% else %} - Login - Register - {% endif %} - - diff --git a/PruebaFoto/templates/login.html b/PruebaFoto/templates/login.html deleted file mode 100644 index 5e91082..0000000 --- a/PruebaFoto/templates/login.html +++ /dev/null @@ -1,17 +0,0 @@ - - - - -Email: {{ email }}
- {% if photo_url %} -