zetarmany commited on
Commit
e341520
·
verified ·
1 Parent(s): 466ab26

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -48
app.py CHANGED
@@ -1,34 +1,26 @@
1
- # app.py - VERSI 1 FILE (PASTI JALAN)
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 'login' in session:
15
  return f"""
16
  <html>
17
  <body style="font-family: Arial; text-align: center; padding: 50px;">
18
- <h1>Selamat Datang {session['username']}!</h1>
19
- <p>Kamu berhasil login sebagai admin.</p>
20
- <a href="/admin" style="background: blue; color: white; padding: 10px; text-decoration: none;">Panel Admin</a>
21
- <a href="/logout" style="background: red; color: white; padding: 10px; text-decoration: none;">Logout</a>
22
  </body>
23
  </html>
24
  """
25
- else:
26
- return """
27
  <html>
28
  <body style="font-family: Arial; text-align: center; padding: 50px;">
29
  <h1>Galeri Angkatan</h1>
30
- <p>Website galeri foto angkatan.</p>
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 username dan password
43
- if username == ADMIN_USERNAME and password == ADMIN_PASSWORD:
44
- session['login'] = True
45
  session['username'] = username
46
  return redirect('/admin')
47
  else:
48
- return "Login gagal! <a href='/login'>Coba lagi</a>"
49
 
50
- # Form login
51
- return '''
52
- <html>
53
- <body style="font-family: Arial; text-align: center; padding: 50px;">
54
- <h2>Login Admin</h2>
55
- <form method="POST" style="display: inline-block; text-align: left;">
56
- <p>Username: <input type="text" name="username" required></p>
57
- <p>Password: <input type="password" name="password" required></p>
58
- <p><button type="submit" style="background: blue; color: white; padding: 10px;">Login</button></p>
59
- </form>
60
- <p><a href="/">Kembali ke Home</a></p>
61
- </body>
62
- </html>
63
- '''
64
 
65
  @app.route('/admin')
66
  def admin():
67
- if 'login' not in session:
68
  return redirect('/login')
69
-
70
  return f"""
71
- <html>
72
- <body style="font-family: Arial; text-align: center; padding: 50px;">
73
- <h1>Panel Admin</h1>
74
- <p>Halo {session['username']}, ini halaman khusus admin.</p>
75
- <p>Fitur upload akan segera ditambahkan.</p>
76
- <a href="/" style="background: gray; color: white; padding: 10px; text-decoration: none;">Home</a>
77
- <a href="/logout" style="background: red; color: white; padding: 10px; text-decoration: none;">Logout</a>
78
- </body>
79
- </html>
80
- """
81
 
82
  @app.route('/logout')
83
  def logout():
84
- session.clear()
85
  return redirect('/')
86
 
87
  if __name__ == '__main__':
88
- port = int(os.environ.get('PORT', 7860))
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)