File size: 1,878 Bytes
c4dc0b3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from fastapi import APIRouter
import sqlite3
from os import listdir
from os.path import exists
from pydantic import BaseModel
class DataType(BaseModel):
    Email:str
    Password:str
# from jose import jwt,JWTError
UserItemGetRouter=APIRouter(prefix="/Users")
@UserItemGetRouter.post("/GetUserItem")
def adduser(Dat:DataType):
    try:
    
        State=False
        connect=sqlite3.connect("DataBase/DataBase.bd")
        cursor=connect.execute(f'''

                        SELECT UserId,Password FROM Users where Email='{Dat.Email}'

                        ''')

        Data=cursor.fetchall()
        if len(Data)!=0:
            if Data[0][0]==None:
                return  {"Status":False,"Message":"Email or Password Is Incorrect "}
        
        HasedPassword=Data[0][1]
        UserId=Data[0][0]
        State=Dat.Password==HasedPassword
        if not State:
            return {"Status":False,"Message":"Email or Password is not correct"}
        
        cursor=connect.execute(f'''

                        SELECT UserItemName FROM UserItems where UserId={UserId}

                        ''')
        Data=cursor.fetchall()
        if len(Data)!=0:
            
            if Data[0][0]==None:
                return  {"Status":True,"Data":[]}
            else:
                UsersItems=[]
                for i in Data:
                    num=0
                    if exists(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{i[0]}"):
                        num=len(listdir(f"./FaceRecognition/ExtactedFaces/{UserId}/Train/{i[0]}"))
                    
                    UsersItems.append({"Name":i[0],"NumImages":num})
                return  {"Status":True,"Data":UsersItems}
        
        return {"Status":False,"Message":[]}
    except Exception as e:
        return {"Status":False,"Message":e}