def pincode(request): if request.method == 'POST': # pin = json.loads(request.body)["pin"] code_entered = request.POST.get("pin") logger.debug("code_entered: %s" % code_entered) log = CodeLog(code_entered=code_entered, success=False) now = timezone.localtime(timezone.now()) status = "FAIL" try: door_code = DoorCode.objects.filter(code=code_entered).first() if door_code: log.code = door_code log.user = door_code.user if door_code.start > now: status = "TOOEARLY" else: if door_code.end and door_code.end < now: status = "EXPIRED" else: delay_sec = int(settings.UNLOCK_DELAY) door.unlock(delay_sec) status = "UNLOCKED" log.success = True else: door.alarm(delay_sec=1) status = "ALARM" except: pass log.status = status log.save() return HttpResponse(status, content_type="text/plain")
def mobile(request): if request.method == 'POST': action = request.POST.get("action") action = action.lower() logger.debug("Action=%s" % action) if action == 'bell': door.bell() elif action == 'alarm': door.alarm() elif action == 'unlock': door.unlock() return render(request, "mobile.html", {})