-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnew_verification.py
89 lines (82 loc) · 2.93 KB
/
new_verification.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
# Verification module
import time
import datetime
import config
import cv2
import tkinter as tk
# Verification functions against DB records
def check_qrcode(data):
if len(data.split('|'))!=3:
print("Wrong data")
return False
hashString=data.split('|')[0]
id=data.split('|')[1]
gene_time_string=data.split('|')[2]
gene_time=float(gene_time_string)
curr_time=time.time()
total_seconds=curr_time-gene_time
if total_seconds<config.threshold:
r = config.dba.check_hashString(hashString, id, gene_time_string)
if r:
config.user_eppn = r['eppn']
config.relay.signal("QR Code") # relay_on()
show_access()
return r
else:
print("Time expired.")
return False
def check_card(cardID):
r = config.dba.get_by_cardID(cardID)
if r:
# A person can only entered once in one minute
if(r['lastAccessTime']!=''):
current = datetime.datetime.strptime(time.ctime(), "%a %b %d %H:%M:%S %Y")
last= datetime.datetime.strptime(r['lastAccessTime'], "%a %b %d %H:%M:%S %Y")
diff = current.timestamp()-last.timestamp()
if (diff < 60):
print("You have entered in the past one minute")
return False
r = config.dba.update_time_by_cardID(cardID)
config.user_eppn = r['eppn']
show_access()
return r
return False
def check_pin(eppn, pin):
r = config.dbc.get_by_eppn(eppn)
config.padON = False
if r and r['pin'] == pin:
config.user_eppn = r['eppn']
show_access()
return r
return False
def check_face(eppn):
r = config.dbc.get_by_eppn(eppn)
if r and r['eppn'] == eppn:
# A person can only entered once in one minute
if(r['lastAccessTime']!=''):
current = datetime.datetime.strptime(time.ctime(), "%a %b %d %H:%M:%S %Y")
last= datetime.datetime.strptime(r['lastAccessTime'], "%a %b %d %H:%M:%S %Y")
diff = current.timestamp()-last.timestamp()
if (diff < 60):
print("You have entered in the past one minute")
return False
r = config.dba.update_time_by_eppn(eppn)
config.user_eppn = r['eppn']
config.relay.signal("Face")
show_access()
return r
return False
def show_access():
cv2.namedWindow ("accgranted", cv2.WINDOW_NORMAL)
cv2.startWindowThread()
cv2.setWindowProperty ('accgranted', cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
root = tk.Tk()
sw = root.winfo_screenwidth()
sh = root.winfo_screenheight()
image = cv2.imread("access.png")
image = cv2.resize(image,(sh, sh))
w,h,c = image.shape
image = cv2.copyMakeBorder( image, int((sh-h)/2), int((sh-h)/2), int((sw-w)/2), int((sw-w)/2), 0)
cv2.imshow('accgranted',image)
time.sleep(1)
cv2.destroyWindow('accgranted')