Spaces:
Sleeping
Sleeping
Session expiry set 24Hr and Admin storage display in MB
Browse files- app/admin/admin_functions.py +6 -2
- app/admin/templates/registration_success.html +3 -3
- app/api/userlogin.py +2 -1
- app/main.py +1 -1
app/admin/admin_functions.py
CHANGED
@@ -68,10 +68,14 @@ def verify_admin_password(submitted_user: str, submitted_password: str) -> bool:
|
|
68 |
|
69 |
return False
|
70 |
|
71 |
-
|
72 |
def get_disk_usage(path="/home/user/data"):
|
73 |
total, used, free = shutil.disk_usage(path)
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
# Additional Admin Functions
|
77 |
# we could include other administrative functionalities here, such as:
|
|
|
68 |
|
69 |
return False
|
70 |
|
|
|
71 |
def get_disk_usage(path="/home/user/data"):
|
72 |
total, used, free = shutil.disk_usage(path)
|
73 |
+
# Convert bytes to MB by dividing by 2^20
|
74 |
+
return {
|
75 |
+
"total": total / (2**20),
|
76 |
+
"used": used / (2**20),
|
77 |
+
"free": free / (2**20)
|
78 |
+
}
|
79 |
|
80 |
# Additional Admin Functions
|
81 |
# we could include other administrative functionalities here, such as:
|
app/admin/templates/registration_success.html
CHANGED
@@ -7,9 +7,9 @@
|
|
7 |
<h1>Registration Successful!</h1>
|
8 |
<div>
|
9 |
<h2>Disk Usage:</h2>
|
10 |
-
<p>Total: {{ disk_usage.total }}
|
11 |
-
<p>Used: {{ disk_usage.used }}
|
12 |
-
<p>Free: {{ disk_usage.free }}
|
13 |
</div>
|
14 |
</body>
|
15 |
</html>
|
|
|
7 |
<h1>Registration Successful!</h1>
|
8 |
<div>
|
9 |
<h2>Disk Usage:</h2>
|
10 |
+
<p>Total: {{ "%.2f"|format(disk_usage.total) }} MB</p>
|
11 |
+
<p>Used: {{ "%.2f"|format(disk_usage.used) }} MB</p>
|
12 |
+
<p>Free: {{ "%.2f"|format(disk_usage.free) }} MB</p>
|
13 |
</div>
|
14 |
</body>
|
15 |
</html>
|
app/api/userlogin.py
CHANGED
@@ -9,6 +9,7 @@ import uuid
|
|
9 |
|
10 |
router = APIRouter()
|
11 |
L2_FACE_THRESHOLD = 0.85 # distance value closer to 0 =>best match, >1 =>poor match
|
|
|
12 |
|
13 |
async def verify_user_face(file_path: str) -> Optional[dict]:
|
14 |
# Assuming `get_user_cropped_image_from_photo` returns the cropped face as expected by ChromaDB
|
@@ -46,7 +47,7 @@ async def user_login(file: UploadFile = File(...)):
|
|
46 |
access_token = create_access_token(data={"sub": user_id, "name": metadata["name"], "role": metadata["role"]})
|
47 |
|
48 |
# Calculate expiration time for the token
|
49 |
-
expires_at = (datetime.utcnow() + timedelta(minutes=
|
50 |
|
51 |
# Store the token in TinyDB
|
52 |
tinydb_helper.insert_token(user_id, access_token, expires_at)
|
|
|
9 |
|
10 |
router = APIRouter()
|
11 |
L2_FACE_THRESHOLD = 0.85 # distance value closer to 0 =>best match, >1 =>poor match
|
12 |
+
SESSION_VALIDITY = 24 * 60 # Token expires after 24 hours
|
13 |
|
14 |
async def verify_user_face(file_path: str) -> Optional[dict]:
|
15 |
# Assuming `get_user_cropped_image_from_photo` returns the cropped face as expected by ChromaDB
|
|
|
47 |
access_token = create_access_token(data={"sub": user_id, "name": metadata["name"], "role": metadata["role"]})
|
48 |
|
49 |
# Calculate expiration time for the token
|
50 |
+
expires_at = (datetime.utcnow() + timedelta(minutes=SESSION_VALIDITY)).isoformat() # Example expiration time
|
51 |
|
52 |
# Store the token in TinyDB
|
53 |
tinydb_helper.insert_token(user_id, access_token, expires_at)
|
app/main.py
CHANGED
@@ -79,7 +79,7 @@ async def handle_user_registration(request: Request, email: str = Form(...), nam
|
|
79 |
# Redirect or display a success message
|
80 |
return templates.TemplateResponse("registration_success.html", {
|
81 |
"request": request,
|
82 |
-
"disk_usage": disk_usage
|
83 |
})
|
84 |
else:
|
85 |
# Reload registration page with error message
|
|
|
79 |
# Redirect or display a success message
|
80 |
return templates.TemplateResponse("registration_success.html", {
|
81 |
"request": request,
|
82 |
+
"disk_usage": disk_usage
|
83 |
})
|
84 |
else:
|
85 |
# Reload registration page with error message
|