Spaces:
Running
Running
| from dotenv import load_dotenv | |
| import os | |
| from flask import Flask, request, render_template, redirect, url_for, make_response | |
| load_dotenv() | |
| app = Flask(__name__) | |
| def login(): | |
| username = request.form.get('username') | |
| password = request.form.get('password') | |
| # Validate against environment variables | |
| if username == os.getenv("ADMIN_USERNAME") and password == os.getenv("ADMIN_PASSWORD"): | |
| return "Login successful!" | |
| return "Invalid username or password!" | |
| # Hardcoded user database (replace with real database in production) | |
| users = { | |
| "admin": "1234", | |
| "user1": "password" | |
| } | |
| def landing_page(): | |
| # Render the landing page HTML | |
| return render_template('index.html') # Ensure this file is in the "templates" folder | |
| def login(): | |
| username = request.form.get('username') | |
| password = request.form.get('password') | |
| # Validate credentials | |
| if username in users and users[username] == password: | |
| response = make_response(redirect(url_for('landing_page'))) | |
| response.set_cookie('logged_in', 'true', max_age=3600) # Session cookie for 1 hour | |
| response.set_cookie('username', username, max_age=3600) | |
| return response | |
| return "Invalid credentials. Please try again." | |
| def logout(): | |
| response = make_response(redirect(url_for('landing_page'))) | |
| response.delete_cookie('logged_in') | |
| response.delete_cookie('username') | |
| return response | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=7860) # Use port 7860 for Hugging Face Spaces |