Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,34 +1,26 @@
|
|
| 1 |
-
# app.py - VERSI
|
| 2 |
-
import os
|
| 3 |
from flask import Flask, request, redirect, session
|
| 4 |
|
| 5 |
app = Flask(__name__)
|
| 6 |
app.secret_key = 'kunci-rahasia-123'
|
| 7 |
|
| 8 |
-
# Data admin (langsung di sini)
|
| 9 |
-
ADMIN_USERNAME = "Hilbraaaam"
|
| 10 |
-
ADMIN_PASSWORD = "Ketua Angkatan 24-26"
|
| 11 |
-
|
| 12 |
@app.route('/')
|
| 13 |
def home():
|
| 14 |
-
if '
|
| 15 |
return f"""
|
| 16 |
<html>
|
| 17 |
<body style="font-family: Arial; text-align: center; padding: 50px;">
|
| 18 |
-
<h1>Selamat
|
| 19 |
-
<
|
| 20 |
-
<a href="/
|
| 21 |
-
<a href="/logout" style="background: red; color: white; padding: 10px; text-decoration: none;">Logout</a>
|
| 22 |
</body>
|
| 23 |
</html>
|
| 24 |
"""
|
| 25 |
-
|
| 26 |
-
return """
|
| 27 |
<html>
|
| 28 |
<body style="font-family: Arial; text-align: center; padding: 50px;">
|
| 29 |
<h1>Galeri Angkatan</h1>
|
| 30 |
-
<
|
| 31 |
-
<a href="/login" style="background: green; color: white; padding: 10px; text-decoration: none;">Login Admin</a>
|
| 32 |
</body>
|
| 33 |
</html>
|
| 34 |
"""
|
|
@@ -39,51 +31,46 @@ def login():
|
|
| 39 |
username = request.form.get('username')
|
| 40 |
password = request.form.get('password')
|
| 41 |
|
| 42 |
-
# Cek
|
| 43 |
-
if username ==
|
| 44 |
-
session['login'] = True
|
| 45 |
session['username'] = username
|
| 46 |
return redirect('/admin')
|
| 47 |
else:
|
| 48 |
-
return "
|
| 49 |
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
<
|
| 59 |
-
|
| 60 |
-
<
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
'''
|
| 64 |
|
| 65 |
@app.route('/admin')
|
| 66 |
def admin():
|
| 67 |
-
if '
|
| 68 |
return redirect('/login')
|
| 69 |
-
|
| 70 |
return f"""
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
<
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
"""
|
| 81 |
|
| 82 |
@app.route('/logout')
|
| 83 |
def logout():
|
| 84 |
-
session.
|
| 85 |
return redirect('/')
|
| 86 |
|
| 87 |
if __name__ == '__main__':
|
| 88 |
-
|
| 89 |
-
app.run(host='0.0.0.0', port=port)
|
|
|
|
| 1 |
+
# app.py - VERSI TEST (PASTI JALAN)
|
|
|
|
| 2 |
from flask import Flask, request, redirect, session
|
| 3 |
|
| 4 |
app = Flask(__name__)
|
| 5 |
app.secret_key = 'kunci-rahasia-123'
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
@app.route('/')
|
| 8 |
def home():
|
| 9 |
+
if 'username' in session:
|
| 10 |
return f"""
|
| 11 |
<html>
|
| 12 |
<body style="font-family: Arial; text-align: center; padding: 50px;">
|
| 13 |
+
<h1>Selamat datang {session['username']}!</h1>
|
| 14 |
+
<a href="/admin" style="background: blue; color: white; padding: 10px;">Admin</a>
|
| 15 |
+
<a href="/logout" style="background: red; color: white; padding: 10px;">Logout</a>
|
|
|
|
| 16 |
</body>
|
| 17 |
</html>
|
| 18 |
"""
|
| 19 |
+
return """
|
|
|
|
| 20 |
<html>
|
| 21 |
<body style="font-family: Arial; text-align: center; padding: 50px;">
|
| 22 |
<h1>Galeri Angkatan</h1>
|
| 23 |
+
<a href="/login" style="background: green; color: white; padding: 10px;">Login Admin</a>
|
|
|
|
| 24 |
</body>
|
| 25 |
</html>
|
| 26 |
"""
|
|
|
|
| 31 |
username = request.form.get('username')
|
| 32 |
password = request.form.get('password')
|
| 33 |
|
| 34 |
+
# Cek login
|
| 35 |
+
if username == 'Hilbraaaam' and password == 'Ketua Angkatan 24-26':
|
|
|
|
| 36 |
session['username'] = username
|
| 37 |
return redirect('/admin')
|
| 38 |
else:
|
| 39 |
+
return "LOGIN GAGAL! <a href='/login'>Coba lagi</a>"
|
| 40 |
|
| 41 |
+
return """
|
| 42 |
+
<html>
|
| 43 |
+
<body style="font-family: Arial; text-align: center; padding: 50px;">
|
| 44 |
+
<h2>Login Admin</h2>
|
| 45 |
+
<form method="POST">
|
| 46 |
+
<p>Username: <input type="text" name="username" required></p>
|
| 47 |
+
<p>Password: <input type="password" name="password" required></p>
|
| 48 |
+
<button type="submit">Login</button>
|
| 49 |
+
</form>
|
| 50 |
+
<p><a href="/">Kembali</a></p>
|
| 51 |
+
</body>
|
| 52 |
+
</html>
|
| 53 |
+
"""
|
|
|
|
| 54 |
|
| 55 |
@app.route('/admin')
|
| 56 |
def admin():
|
| 57 |
+
if 'username' not in session:
|
| 58 |
return redirect('/login')
|
|
|
|
| 59 |
return f"""
|
| 60 |
+
<html>
|
| 61 |
+
<body style="font-family: Arial; text-align: center; padding: 50px;">
|
| 62 |
+
<h1>Panel Admin</h1>
|
| 63 |
+
<p>Halo {session['username']}!</p>
|
| 64 |
+
<a href="/" style="background: gray; color: white; padding: 10px;">Home</a>
|
| 65 |
+
<a href="/logout" style="background: red; color: white; padding: 10px;">Logout</a>
|
| 66 |
+
</body>
|
| 67 |
+
</html>
|
| 68 |
+
"""
|
|
|
|
| 69 |
|
| 70 |
@app.route('/logout')
|
| 71 |
def logout():
|
| 72 |
+
session.pop('username', None)
|
| 73 |
return redirect('/')
|
| 74 |
|
| 75 |
if __name__ == '__main__':
|
| 76 |
+
app.run(host='0.0.0.0', port=7860)
|
|
|