BuildTools commited on
Commit
32cd1b5
·
1 Parent(s): 18cd205
Files changed (5) hide show
  1. Dockerfile +1 -1
  2. __pycache__/main.cpython-312.pyc +0 -0
  3. app.py +0 -21
  4. main.py +39 -0
  5. requirements.txt +1 -1
Dockerfile CHANGED
@@ -13,4 +13,4 @@ COPY --chown=user ./requirements.txt requirements.txt
13
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
  COPY --chown=user . /app
16
- CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
 
13
  RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
 
15
  COPY --chown=user . /app
16
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
__pycache__/main.cpython-312.pyc ADDED
Binary file (1.85 kB). View file
 
app.py DELETED
@@ -1,21 +0,0 @@
1
- from pymongo import MongoClient
2
- from fastapi import FastAPI
3
- from bson import ObjectId # Pour gérer les ObjectId
4
-
5
- # Connexion à MongoDB Atlas
6
- uri = "mongodb+srv://lebaykserver:[email protected]/"
7
- client = MongoClient(uri)
8
- database = client["IA_SIGNATURE"]
9
- collection = database["USER"]
10
-
11
- # Initialisation de FastAPI
12
- app = FastAPI()
13
-
14
- @app.get("/user")
15
- async def read_user():
16
- user = collection.find_one()
17
-
18
- if user:
19
- user["_id"] = str(user["_id"]) # Convertir l'ObjectId en string
20
- return user
21
- return {"message": "Aucun utilisateur trouvé"}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
main.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI, HTTPException
2
+ from pydantic import BaseModel
3
+ from pymongo import MongoClient
4
+ from bson import ObjectId
5
+ import hashlib
6
+
7
+ # Configuration MongoDB
8
+ client = MongoClient("mongodb+srv://lebaykserver:[email protected]/")
9
+ db = client["IA_SIGNATURE"]
10
+ users_collection = db["USER"]
11
+
12
+ # Créer une instance de FastAPI
13
+ app = FastAPI()
14
+
15
+ # Modèle pour valider les données reçues
16
+ class User(BaseModel):
17
+ username: str
18
+ password: str
19
+ etablissement: str
20
+
21
+ # Fonction pour hasher le mot de passe
22
+ def hash_password(password: str) -> str:
23
+ return hashlib.sha256(password.encode()).hexdigest()
24
+
25
+ @app.post("/login/")
26
+ async def login_user(user: User):
27
+ # Recherche de l'utilisateur dans la base de données
28
+ existing_user = users_collection.find_one({"username": user.username})
29
+
30
+ if not existing_user:
31
+ raise HTTPException(status_code=400, detail="Utilisateur non trouvé")
32
+
33
+ # Vérifier si le mot de passe est correct
34
+ hashed_password = hash_password(user.password)
35
+
36
+ if existing_user["password"] != hashed_password:
37
+ raise HTTPException(status_code=400, detail="Mot de passe incorrect")
38
+
39
+ return {"message": "Connexion réussie"}
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
  fastapi
2
  uvicorn[standard]
3
- pymongo
 
1
  fastapi
2
  uvicorn[standard]
3
+ pymongo