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