Ejemplo n.º 1
0
    def handle(self, *args, **kwargs):
        r = get_redis_connection('default')

        for card_hash, rawdata in rfid_api.cards_read():

            card = rfid_api.card_validate(card_hash)
            if not card:
                continue

            if not card.user_id:
                r.set('rfid_last_unpaired', card.id)
                notification_api.notify_subject(
                    b'door_event',
                    json.dumps({
                        'event': 'CARD_UNPAIRED',
                        'card_id': card.id,
                        'rawdata': rawdata.hex(),
                    }))
                continue

            # TODO:
            # - lookup user_name and send it to the door open

            hackman_api.door_open_if_paid(
                card.user_id,
                source="CARD",
                rawdata=rawdata,
            )
Ejemplo n.º 2
0
    def handle(self, *args, **kwargs):
        r = get_redis_connection('default')

        for card_hash in rfid_api.cards_read():

            card = rfid_api.card_validate(card_hash)
            if not card:
                continue

            if not card.user_id:
                r.set('rfid_last_unpaired', card.id)
                notification_api.notify_subject(b'door_event', json.dumps({
                    'event': 'CARD_UNPAIRED',
                    'card_id': card.id
                }))
                continue

            hackman_api.door_open_if_paid(card.user_id)
Ejemplo n.º 3
0
def door_open(request, _door_api=None):
    from hackman import api as hackman_api

    if not hackman_api.door_open_if_paid(request.user.id, _door_api):
        return http.HttpResponseForbidden('<h1>You have not paid!</h1>')

    try:
        messages.add_message(request, messages.SUCCESS, 'Opened door!')
    except MessageFailure:  # pragma: no cover
        pass

    return shortcuts.redirect('/')
Ejemplo n.º 4
0
def door_open(request, _door_api=None):
    from hackman import api as hackman_api

    if not hackman_api.door_open_if_paid(request.user.id, _door_api):
        result = shortcuts.render(request, 'unpaid.jinja2')
        result.status_code = 403
        return result

    try:
        messages.add_message(request, messages.SUCCESS, 'Opened door!')
    except MessageFailure:  # pragma: no cover
        pass

    return shortcuts.redirect('/')