Added ID validation
This commit is contained in:
parent
47e75ecd1a
commit
9e8e03ac25
25
validate.py
25
validate.py
@ -3,6 +3,7 @@
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import time
|
||||
import json
|
||||
import RPi.GPIO as IO
|
||||
import zmq
|
||||
|
||||
@ -51,8 +52,12 @@ def read_loop():
|
||||
socket = context.socket(zmq.SUB)
|
||||
socket.setsockopt(zmq.SUBSCRIBE, "")
|
||||
socket.connect(SCANSERVADDRESS)
|
||||
# TODO: Open the access database
|
||||
|
||||
# Open the access database
|
||||
access_raw = open("access.json").read()
|
||||
try:
|
||||
access = json.loads(access_raw)
|
||||
except:
|
||||
raise SystemExit("Could not load access file!")
|
||||
# Initialize the PWM pin for opening the door
|
||||
pwm_pin = setup_pwm()
|
||||
# Open the log file in append mode
|
||||
@ -63,21 +68,23 @@ def read_loop():
|
||||
while True:
|
||||
# Read in the ID
|
||||
scanned_id = socket.recv()
|
||||
# TODO: Check if the ID is authorized
|
||||
authorized = True
|
||||
|
||||
|
||||
# Determine ID authorization
|
||||
authorized = id in access and "authorized" in access[id] and access[id]["authorized"]
|
||||
user = access[id]["user"] if id in access and "user" in access[id] else "unknown id"
|
||||
# If the user is not authorized, deny access
|
||||
if not authorized:
|
||||
s = timestamped("##### denied\n")
|
||||
s = timestamped("Denied {} ({})\n".format(id, user))
|
||||
log_file.write(s)
|
||||
print s,
|
||||
# If the user is authorized, perform the unlock procedure
|
||||
else:
|
||||
s = timestamped("##### <Username> validated\n")
|
||||
s = timestamped("Validated {} {}\n".format(id, user))
|
||||
log_file.write(s)
|
||||
print s,
|
||||
# TODO: Play open tone
|
||||
# TODO: Run unlock procedure
|
||||
if "sound" in access[id]:
|
||||
pass
|
||||
# Run unlock procedure
|
||||
unlock_door(pwm_pin)
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user