added door sec level and user sec level check
This commit is contained in:
parent
d2c224145e
commit
c491ae0db3
79
main.py
79
main.py
@ -58,6 +58,8 @@ doorID = config.get('Setup', 'doorID')
|
||||
gotAaguid = None
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
|
||||
secLevel = 0
|
||||
|
||||
greenLed = 14
|
||||
redLed = 4
|
||||
|
||||
@ -96,6 +98,8 @@ class CliInteraction(UserInteraction):
|
||||
print("User Verification required.")
|
||||
return True
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
|
||||
GPIO.output(door, GPIO.LOW)
|
||||
@ -231,6 +235,77 @@ while True:
|
||||
)
|
||||
|
||||
print("Credential authenticated!")
|
||||
print("CLIENT DATA:", result.client_data)
|
||||
print()
|
||||
print("AUTH DATA:", result.authenticator_data)
|
||||
# GPIO.output(14, GPIO.LOW)
|
||||
|
||||
conn = None
|
||||
try:
|
||||
# Connect to the PostgreSQL server
|
||||
conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host)
|
||||
cur = conn.cursor()
|
||||
select_query = '''
|
||||
SELECT sec_level
|
||||
FROM users
|
||||
WHERE "user_id" = %s;
|
||||
'''
|
||||
# Execute the SQL query
|
||||
cur.execute(select_query, (result[1]))
|
||||
|
||||
# Fetch the results
|
||||
result = None
|
||||
result = cur.fetchone()
|
||||
if result:
|
||||
userSecLevel = result[0]
|
||||
|
||||
else:
|
||||
badCred()
|
||||
raise Exception
|
||||
|
||||
# Close communication with the database
|
||||
cur.close()
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
print(error)
|
||||
raise Exception
|
||||
finally:
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
conn = None
|
||||
try:
|
||||
# Connect to the PostgreSQL server
|
||||
conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host)
|
||||
cur = conn.cursor()
|
||||
select_query = '''
|
||||
SELECT sec_level
|
||||
FROM door
|
||||
WHERE "door_id" = %s;
|
||||
'''
|
||||
# Execute the SQL query
|
||||
cur.execute(select_query, (doorID))
|
||||
|
||||
# Fetch the results
|
||||
result = None
|
||||
result = cur.fetchone()
|
||||
if result:
|
||||
doorSecLevel = result[0]
|
||||
|
||||
else:
|
||||
badCred()
|
||||
raise Exception
|
||||
|
||||
# Close communication with the database
|
||||
cur.close()
|
||||
except (Exception, psycopg2.DatabaseError) as error:
|
||||
print(error)
|
||||
raise Exception
|
||||
finally:
|
||||
if conn is not None:
|
||||
conn.close()
|
||||
|
||||
if doorSecLevel < userSecLevel:
|
||||
raise Exception
|
||||
|
||||
GPIO.output(redLed, GPIO.LOW)
|
||||
for i in range(2):
|
||||
@ -244,10 +319,6 @@ while True:
|
||||
time.sleep(5)
|
||||
GPIO.output(greenLed, GPIO.LOW)
|
||||
|
||||
print("CLIENT DATA:", result.client_data)
|
||||
print()
|
||||
print("AUTH DATA:", result.authenticator_data)
|
||||
# GPIO.output(14, GPIO.LOW)
|
||||
|
||||
except Exception as e:
|
||||
print("Authentication Failed!")
|
||||
|
Loading…
Reference in New Issue
Block a user