forked from arti/doors
Add kdoorpi api endpoint
This commit is contained in:
parent
a9abf1eba0
commit
6c6105df94
@ -145,6 +145,9 @@ class DB:
|
|||||||
)
|
)
|
||||||
return cur.fetchone()
|
return cur.fetchone()
|
||||||
|
|
||||||
|
def add_keycard(self, user_id, card_uid, name):
|
||||||
|
self.add_keycards([(user_id, card_uid, name)])
|
||||||
|
|
||||||
def add_keycards(self, keycards):
|
def add_keycards(self, keycards):
|
||||||
self.db.executemany("""
|
self.db.executemany("""
|
||||||
insert into keycards(user_id, card_uid, name)
|
insert into keycards(user_id, card_uid, name)
|
||||||
@ -156,6 +159,24 @@ class DB:
|
|||||||
cur = self.db.execute("select id, name, created, disabled from keycards where user_id = ?", (user_id,))
|
cur = self.db.execute("select id, name, created, disabled from keycards where user_id = ?", (user_id,))
|
||||||
return cur.fetchall()
|
return cur.fetchall()
|
||||||
|
|
||||||
|
def list_all_keycards(self):
|
||||||
|
cur = self.db.execute("""
|
||||||
|
select
|
||||||
|
users.id as user_id,
|
||||||
|
users.user as user,
|
||||||
|
users.full_name as full_name,
|
||||||
|
k.id as card_id,
|
||||||
|
k.card_uid as card_uid
|
||||||
|
from users
|
||||||
|
join
|
||||||
|
keycards k on users.id = k.user_id
|
||||||
|
where
|
||||||
|
(users.disabled = 0 or users.disabled is null)
|
||||||
|
and
|
||||||
|
(k.disabled is 0 or k.disabled is null)
|
||||||
|
""")
|
||||||
|
return cur.fetchall()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def import_ad(json_file):
|
def import_ad(json_file):
|
||||||
with open(json_file) as fp:
|
with open(json_file) as fp:
|
||||||
|
@ -152,3 +152,9 @@ def log(db):
|
|||||||
@view("doors.html")
|
@view("doors.html")
|
||||||
def doors(db):
|
def doors(db):
|
||||||
return {"doors":[]}
|
return {"doors":[]}
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME: Add door api auth
|
||||||
|
@app.route("/api/v1/cards", skip=[check_auth])
|
||||||
|
def api_list_cards(db):
|
||||||
|
return {"keycards":[dict(card) for card in db.list_all_keycards()]}
|
||||||
|
Loading…
Reference in New Issue
Block a user