Update app.py
Browse files
app.py
CHANGED
|
@@ -93,34 +93,22 @@ def authenticate():
|
|
| 93 |
'You have to login with proper credentials', 401,
|
| 94 |
{'WWW-Authenticate': 'Basic realm="Login Required"'})
|
| 95 |
|
| 96 |
-
def protected(f):
|
| 97 |
-
@wraps(f)
|
| 98 |
-
def decorated(*args, **kwargs):
|
| 99 |
-
auth = request.authorization
|
| 100 |
-
if not auth or not check_auth(auth.username, auth.password):
|
| 101 |
-
return authenticate()
|
| 102 |
-
return f(*args, **kwargs)
|
| 103 |
-
return decorated
|
| 104 |
-
|
| 105 |
|
| 106 |
-
# --- PENGATURAN ADMIN PANEL (VERSI
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
return super().dispatch_request(*args, **kwargs)
|
| 114 |
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
pass
|
| 118 |
|
| 119 |
-
class SecureModelView(
|
| 120 |
pass
|
| 121 |
|
| 122 |
-
|
| 123 |
-
class DashboardView(SecureAdminIndexView):
|
| 124 |
def get_sales_data(self):
|
| 125 |
"""Query data penjualan untuk 7 hari terakhir."""
|
| 126 |
today = date.today()
|
|
|
|
| 93 |
'You have to login with proper credentials', 401,
|
| 94 |
{'WWW-Authenticate': 'Basic realm="Login Required"'})
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
+
# --- PENGATURAN ADMIN PANEL (VERSI BENAR & FINAL) ---
|
| 98 |
|
| 99 |
+
class AuthMixin:
|
| 100 |
+
"""Mixin untuk menambahkan autentikasi ke view admin."""
|
| 101 |
+
def is_accessible(self):
|
| 102 |
+
auth = request.authorization
|
| 103 |
+
return auth and check_auth(auth.username, auth.password)
|
|
|
|
| 104 |
|
| 105 |
+
def inaccessible_callback(self, name, **kwargs):
|
| 106 |
+
return authenticate()
|
|
|
|
| 107 |
|
| 108 |
+
class SecureModelView(AuthMixin, ModelView):
|
| 109 |
pass
|
| 110 |
|
| 111 |
+
class DashboardView(AuthMixin, AdminIndexView):
|
|
|
|
| 112 |
def get_sales_data(self):
|
| 113 |
"""Query data penjualan untuk 7 hari terakhir."""
|
| 114 |
today = date.today()
|