From: Christian Heller Date: Mon, 9 Nov 2020 20:59:48 +0000 (+0100) Subject: Use b64 for card IDs. X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/unset_cookie?a=commitdiff_plain;h=d4956dd8a9031b23be3bfd9fe791d413c64e919d;p=guiltcards Use b64 for card IDs. --- diff --git a/guiltcards.py b/guiltcards.py index 92cd49b..aa77ce3 100755 --- a/guiltcards.py +++ b/guiltcards.py @@ -2,6 +2,7 @@ from bottle import debug, run, default_app, get, view, request, post, redirect import os import json +import base64 web_path = '/guiltcards' cards_dir = 'cards/' @@ -12,7 +13,7 @@ def get_card_data(card_id): path_card = cards_dir + card_id if os.path.exists(path_card): with open(path_card, 'r') as f: - data = json.loads(f.read())#f.read() + data = json.loads(f.read()) else: data = {'title': '?', 'prompt':'?', @@ -30,12 +31,16 @@ def list_cards(): if not os.path.exists(cards_dir): os.makedirs(cards_dir) card_ids = os.listdir(cards_dir) + cards = {} + for card_id in card_ids: + cards[card_id] = base64.b64decode(card_id).decode() return dict(web_path=web_path, - card_ids=card_ids) + cards=cards) @get(web_path + '/cards/') def new_card(): - card_id = request.query.get('card_id') + card_name = request.query.get('card_name') + card_id = base64.b64encode(card_name.encode()).decode() redirect(web_path + '/cards/' + card_id + '/form') @get(web_path + '/cards//view') @@ -81,7 +86,9 @@ def card_form(card_id): @get(web_path + '/cards//delete') @view('delete_card') def delete_card_ask(card_id): + card_name = base64.b64decode(card_id.encode()).decode() return dict(web_path=web_path, + card_name=card_name, card_id=card_id) @post(web_path + '/cards//delete') diff --git a/views/cards.tpl b/views/cards.tpl index dbf5ea6..758fe22 100644 --- a/views/cards.tpl +++ b/views/cards.tpl @@ -2,12 +2,12 @@
-add another? name: +add another? name:
diff --git a/views/delete_card.tpl b/views/delete_card.tpl index 45b6449..cd1ec0f 100644 --- a/views/delete_card.tpl +++ b/views/delete_card.tpl @@ -2,7 +2,7 @@
- +
Nah, better not …