Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, request, render_template, redirect, url_for, make_response
|
| 2 |
+
|
| 3 |
+
app = Flask(__name__)
|
| 4 |
+
|
| 5 |
+
# Hardcoded user database (replace with real database in production)
|
| 6 |
+
users = {
|
| 7 |
+
"admin": "jtvidela",
|
| 8 |
+
"user1": "josvi981965"
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
@app.route('/')
|
| 12 |
+
def landing_page():
|
| 13 |
+
# Render the landing page HTML
|
| 14 |
+
return render_template('index.html') # Ensure this file is in the "templates" folder
|
| 15 |
+
|
| 16 |
+
@app.route('/login', methods=['POST'])
|
| 17 |
+
def login():
|
| 18 |
+
username = request.form.get('username')
|
| 19 |
+
password = request.form.get('password')
|
| 20 |
+
|
| 21 |
+
# Validate credentials
|
| 22 |
+
if username in users and users[username] == password:
|
| 23 |
+
response = make_response(redirect(url_for('landing_page')))
|
| 24 |
+
response.set_cookie('logged_in', 'true', max_age=3600) # Session cookie for 1 hour
|
| 25 |
+
response.set_cookie('username', username, max_age=3600)
|
| 26 |
+
return response
|
| 27 |
+
|
| 28 |
+
return "Invalid credentials. Please try again."
|
| 29 |
+
|
| 30 |
+
@app.route('/logout')
|
| 31 |
+
def logout():
|
| 32 |
+
response = make_response(redirect(url_for('landing_page')))
|
| 33 |
+
response.delete_cookie('logged_in')
|
| 34 |
+
response.delete_cookie('username')
|
| 35 |
+
return response
|
| 36 |
+
|
| 37 |
+
if __name__ == '__main__':
|
| 38 |
+
app.run(host='0.0.0.0', port=7860) # Use port 7860 for Hugging Face Spaces
|