-
Notifications
You must be signed in to change notification settings - Fork 0
/
Registration.py
121 lines (102 loc) · 3.87 KB
/
Registration.py
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import face_recognition as fr
import numpy as np
from os import path
import pickle
import selfie
import reg_data
from datetime import date,datetime
from Upload_to_storage import get_url
from Upload_to_firestore import Upload
from Export_Data_from_firebase import get_data
notif=""
#Taking input...
def registration(id,name,password):
global notif
if(name == ""):
notif = "Name is required."
return notif
if(id.isdigit()):
id=int(id)
elif(password==""):
notif = "Password is required."
return notif
else:
notif="Invalid ID Please Retry"
return notif
#Checking if file already exists...
exists = path.isfile('./data.dat')
f= True
#If exists then append...
if(exists):
#Read data from the data.dat file and check if id already exists.
fileobj=open("data.dat",'rb')
r_ens,r_ids,r_names=pickle.load(fileobj)
fileobj.close()
if(id in r_ids):
lst=r_ids.tolist()
notif=f"Id= {id} already registered,\nWith Name = {r_names[lst.index(id)]}."
return notif
name=name[0].upper() + name[1:].lower()
# Code for Taking the photo and saving it in f"{name}.jpg"
selfie.input(id,name)
#Code for creating a face_encodings,id,name array of current user.
try:
img1=fr.load_image_file(f"./Images/{id} {name}1.jpg")
en1=fr.face_encodings(img1)[0]
img2=fr.load_image_file(f"./Images/{id} {name}2.jpg")
en2=fr.face_encodings(img2)[0]
Ids=np.array([id,id])
Names=np.array([name,name])
Ens=np.array([en1,en2])
#Appending manuallly..
#Add more data,i.e. the data of current user.
Ens=np.append(r_ens,Ens,axis=0)
Ids=np.append(r_ids,Ids)
Names=np.append(r_names,Names)
#Overwriting the data file with new data.
fileobj1=open("data.dat",'wb')
pickle.dump((Ens,Ids,Names),fileobj1)
Image_Path1=f"Images/{id} {name}1.jpg"
Image=get_url(Image_Path1)
Time=[(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))]
tmp={'User_ID':str(id),'Time':Time,'Name':str(name),'Image':Image,'Date':str(date.today().strftime("%m/%d/%y")),'Password':password}
Upload(tmp,'User_Data')
Upload(tmp,'DateTime')
notif=f"[Id= {id} , Name= {name}] registered."
fileobj1.close()
except:
notif="Please Retry"
f = False
#If not exists then create..
else:
#name=input("Enter Name- ")
name=name[0].upper() + name[1:].lower()
# Code for Taking the photo and saving it in f"{name}.jpg"
selfie.input(id,name)
#Code for creating a face_encodings,id,name array of current user.
try:
img1=fr.load_image_file(f"./Images/{id} {name}1.jpg")
en1=fr.face_encodings(img1)[0]
img2=fr.load_image_file(f"./Images/{id} {name}2.jpg")
en2=fr.face_encodings(img2)[0]
Ids=np.array([id,id])
Names=np.array([name,name])
Ens=np.array([en1,en2])
#Create first data file
fileobj=open("data.dat",'wb')
pickle.dump((Ens,Ids,Names),fileobj)
Image_Path1=f"Images/{id} {name}1.jpg"
Image=get_url(Image_Path1)
Time=[(datetime.now().strftime("%d/%m/%Y %H:%M:%S"))]
tmp={'User_ID':str(id),'Time':Time,'Name':str(name),'Image':Image,'Date':str(date.today().strftime("%m/%d/%y")),'Password':password}
#print(tmp)
Upload(tmp,'User_Data')
Upload(tmp,'DateTime')
notif=f"[Id= {id} , Name= {name}] registered."
fileobj.close()
except:
notif="Please Retry"
f = False
if(f):
reg_data.do(id,password)
return notif