Spaces:
Sleeping
Sleeping
admin logic fix
Browse files
app/admin/admin_functions.py
CHANGED
@@ -4,7 +4,7 @@ import bcrypt
|
|
4 |
|
5 |
|
6 |
# Admin Authentication
|
7 |
-
def verify_admin_password(
|
8 |
"""
|
9 |
Verifies the submitted password against the stored hash.
|
10 |
|
@@ -12,7 +12,9 @@ def verify_admin_password(submitted_password: str, stored_password_hash: str) ->
|
|
12 |
:param stored_password_hash: The hashed password retrieved from a secure store.
|
13 |
:return: True if the password is correct, False otherwise.
|
14 |
"""
|
15 |
-
stored_password = b"
|
|
|
|
|
16 |
|
17 |
stored_password_hash = bcrypt.hashpw(stored_password, bcrypt.gensalt())
|
18 |
|
|
|
4 |
|
5 |
|
6 |
# Admin Authentication
|
7 |
+
def verify_admin_password(submitted_user: str, submitted_password: str) -> bool:
|
8 |
"""
|
9 |
Verifies the submitted password against the stored hash.
|
10 |
|
|
|
12 |
:param stored_password_hash: The hashed password retrieved from a secure store.
|
13 |
:return: True if the password is correct, False otherwise.
|
14 |
"""
|
15 |
+
stored_password = b" "
|
16 |
+
if submitted_user == "admin":
|
17 |
+
stored_password = b"welcome." # Later retrieve from secrets
|
18 |
|
19 |
stored_password_hash = bcrypt.hashpw(stored_password, bcrypt.gensalt())
|
20 |
|
app/admin/templates/user_registration.html
CHANGED
@@ -23,5 +23,8 @@
|
|
23 |
|
24 |
<button type="submit">Register</button>
|
25 |
</form>
|
|
|
|
|
|
|
26 |
</body>
|
27 |
</html>
|
|
|
23 |
|
24 |
<button type="submit">Register</button>
|
25 |
</form>
|
26 |
+
{% if error %}
|
27 |
+
<p class="error"><strong>Error:</strong> {{ error }}
|
28 |
+
{% endif %}
|
29 |
</body>
|
30 |
</html>
|
app/main.py
CHANGED
@@ -30,9 +30,9 @@ async def get_admin_login(request: Request):
|
|
30 |
|
31 |
# Admin Login Handler
|
32 |
@app.post("/admin/login", response_class=HTMLResponse)
|
33 |
-
async def handle_admin_login(request: Request, password: str = Form(...)):
|
34 |
|
35 |
-
if admin.verify_admin_password(password):
|
36 |
# Redirect to user registration page upon successful login
|
37 |
return RedirectResponse(url="/admin/register_user", status_code=303)
|
38 |
else:
|
|
|
30 |
|
31 |
# Admin Login Handler
|
32 |
@app.post("/admin/login", response_class=HTMLResponse)
|
33 |
+
async def handle_admin_login(request: Request, username: str = Form(...), password: str = Form(...)):
|
34 |
|
35 |
+
if admin.verify_admin_password(username, password):
|
36 |
# Redirect to user registration page upon successful login
|
37 |
return RedirectResponse(url="/admin/register_user", status_code=303)
|
38 |
else:
|