Spaces:
Sleeping
Sleeping
Added disk size status in Admin
Browse files- app/admin/admin_functions.py +6 -0
- app/admin/templates/registration_success.html +15 -1
- app/main.py +8 -2
app/admin/admin_functions.py
CHANGED
@@ -2,6 +2,7 @@ from fastapi import HTTPException, UploadFile, File, Form
|
|
2 |
from typing import Optional
|
3 |
import bcrypt
|
4 |
import os
|
|
|
5 |
from ..utils import get_user_cropped_image_from_photo
|
6 |
|
7 |
|
@@ -67,6 +68,11 @@ def verify_admin_password(submitted_user: str, submitted_password: str) -> bool:
|
|
67 |
|
68 |
return False
|
69 |
|
|
|
|
|
|
|
|
|
|
|
70 |
# Additional Admin Functions
|
71 |
# we could include other administrative functionalities here, such as:
|
72 |
# - Listing all registered users.
|
|
|
2 |
from typing import Optional
|
3 |
import bcrypt
|
4 |
import os
|
5 |
+
import shutil
|
6 |
from ..utils import get_user_cropped_image_from_photo
|
7 |
|
8 |
|
|
|
68 |
|
69 |
return False
|
70 |
|
71 |
+
|
72 |
+
def get_disk_usage(path="/home/user/data"):
|
73 |
+
total, used, free = shutil.disk_usage(path)
|
74 |
+
return {"total": total, "used": used, "free": free}
|
75 |
+
|
76 |
# Additional Admin Functions
|
77 |
# we could include other administrative functionalities here, such as:
|
78 |
# - Listing all registered users.
|
app/admin/templates/registration_success.html
CHANGED
@@ -1 +1,15 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>Registration Success</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h1>Registration Successful!</h1>
|
8 |
+
<div>
|
9 |
+
<h2>Disk Usage:</h2>
|
10 |
+
<p>Total: {{ disk_usage.total }} bytes</p>
|
11 |
+
<p>Used: {{ disk_usage.used }} bytes</p>
|
12 |
+
<p>Free: {{ disk_usage.free }} bytes</p>
|
13 |
+
</div>
|
14 |
+
</body>
|
15 |
+
</html>
|
app/main.py
CHANGED
@@ -73,12 +73,18 @@ async def get_user_registration(request: Request):
|
|
73 |
async def handle_user_registration(request: Request, email: str = Form(...), name: str = Form(...), role: str = Form(...), file: UploadFile = File(...)):
|
74 |
user_id = await admin.register_user(user_faces_db, email, name, role, file)
|
75 |
if user_id:
|
|
|
|
|
|
|
76 |
# Redirect or display a success message
|
77 |
-
return templates.TemplateResponse("registration_success.html", {
|
|
|
|
|
|
|
78 |
else:
|
79 |
# Reload registration page with error message
|
80 |
return templates.TemplateResponse("user_registration.html", {"request": request, "error": "Registration failed"})
|
81 |
-
|
82 |
app.include_router(userlogin.router)
|
83 |
app.include_router(userlogout.router)
|
84 |
app.include_router(userchat.router)
|
|
|
73 |
async def handle_user_registration(request: Request, email: str = Form(...), name: str = Form(...), role: str = Form(...), file: UploadFile = File(...)):
|
74 |
user_id = await admin.register_user(user_faces_db, email, name, role, file)
|
75 |
if user_id:
|
76 |
+
# Calculate disk usage
|
77 |
+
disk_usage = admin.get_disk_usage("/home/user/data")
|
78 |
+
|
79 |
# Redirect or display a success message
|
80 |
+
return templates.TemplateResponse("registration_success.html", {
|
81 |
+
"request": request,
|
82 |
+
"disk_usage": disk_usage # This line is crucial
|
83 |
+
})
|
84 |
else:
|
85 |
# Reload registration page with error message
|
86 |
return templates.TemplateResponse("user_registration.html", {"request": request, "error": "Registration failed"})
|
87 |
+
|
88 |
app.include_router(userlogin.router)
|
89 |
app.include_router(userlogout.router)
|
90 |
app.include_router(userchat.router)
|