Spaces:
Sleeping
Sleeping
Added adminfunction
Browse files
app/admin/admin_functions.py
ADDED
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import HTTPException, UploadFile, File, Form
|
2 |
+
from typing import Optional
|
3 |
+
import bcrypt
|
4 |
+
from .database import db # Assuming you have a database module for interacting with ChromaDB
|
5 |
+
|
6 |
+
# Admin Authentication
|
7 |
+
def verify_admin_password(submitted_password: str, stored_password_hash: str) -> bool:
|
8 |
+
"""
|
9 |
+
Verifies the submitted password against the stored hash.
|
10 |
+
|
11 |
+
:param submitted_password: The password submitted by the user.
|
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 |
+
return bcrypt.checkpw(submitted_password.encode('utf-8'), stored_password_hash.encode('utf-8'))
|
16 |
+
|
17 |
+
# User Registration
|
18 |
+
async def register_user(email: str, name: str, role: str, file: UploadFile = File(...)) -> Optional[str]:
|
19 |
+
"""
|
20 |
+
Registers a new user with the provided details and stores the profile picture.
|
21 |
+
|
22 |
+
:param email: The user's email address.
|
23 |
+
:param name: The user's full name.
|
24 |
+
:param role: The user's role (e.g., Student, Teacher).
|
25 |
+
:param file: The profile picture file.
|
26 |
+
:return: User ID of the newly registered user or None if registration failed.
|
27 |
+
"""
|
28 |
+
# Here, you would include logic to:
|
29 |
+
# 1. Process and validate the input data.
|
30 |
+
# 2. Use MTCNN and Facenet (or similar) to process the profile picture.
|
31 |
+
# 3. Store the user's details and the processed picture in ChromaDB.
|
32 |
+
# 4. Return the user ID or None if the registration fails.
|
33 |
+
|
34 |
+
# This is a placeholder for the implementation.
|
35 |
+
pass
|
36 |
+
|
37 |
+
# Additional Admin Functions
|
38 |
+
# You could include other administrative functionalities here, such as:
|
39 |
+
# - Listing all registered users.
|
40 |
+
# - Moderating chat messages or viewing chat history.
|
41 |
+
# - Managing system settings or configurations.
|
42 |
+
|
app/admin/templates/admin_login.html
CHANGED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<head>
|
3 |
+
<title>EduConnect Administration- login page</title>
|
4 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
5 |
+
<link href="static/bootstrap.min.css" rel="stylesheet" media="screen">
|
6 |
+
</head>
|
7 |
+
<body>
|
8 |
+
<div class="container">
|
9 |
+
<h1>Please login</h1>
|
10 |
+
<br>
|
11 |
+
<form action="/admin/login" method="post">
|
12 |
+
<input type="text" placeholder="Username" name="username" value="{{
|
13 |
+
request.form.username }}">
|
14 |
+
<input type="password" placeholder="Password" name="password" value="{{
|
15 |
+
request.form.password }}">
|
16 |
+
<input class="btn btn-default" type="submit" value="Login">
|
17 |
+
</form>
|
18 |
+
{% if error %}
|
19 |
+
<p class="error"><strong>Error:</strong> {{ error }}
|
20 |
+
{% endif %}
|
21 |
+
</div>
|
22 |
+
</body>
|
23 |
+
</html>
|
app/admin/templates/user_registration.html
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<title>User Registration</title>
|
5 |
+
</head>
|
6 |
+
<body>
|
7 |
+
<h2>User Registration</h2>
|
8 |
+
<form action="/admin/register_user" method="post" enctype="multipart/form-data">
|
9 |
+
<label for="email">User ID (Email):</label>
|
10 |
+
<input type="email" id="email" name="email" required><br>
|
11 |
+
|
12 |
+
<label for="name">Name:</label>
|
13 |
+
<input type="text" id="name" name="name" required><br>
|
14 |
+
|
15 |
+
<label for="role">Role:</label>
|
16 |
+
<select id="role" name="role">
|
17 |
+
<option value="Student">Student</option>
|
18 |
+
<option value="Teacher">Teacher</option>
|
19 |
+
</select><br>
|
20 |
+
|
21 |
+
<label for="file">Profile Picture (.jpg):</label>
|
22 |
+
<input type="file" id="file" name="file" accept=".jpg" required><br>
|
23 |
+
|
24 |
+
<button type="submit">Register</button>
|
25 |
+
</form>
|
26 |
+
</body>
|
27 |
+
</html>
|