From 0dd814b33e5c57d3dafce175bd3c19fa26c631ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Sun, 29 Sep 2019 22:45:00 +0200 Subject: [PATCH] fix "user undefined" --- certweb/pubkeys.py | 15 +++++++++++---- certweb/static/style.css | 1 + certweb/templates/pubkeys/index.html | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/certweb/pubkeys.py b/certweb/pubkeys.py index b6bf12d..85650de 100644 --- a/certweb/pubkeys.py +++ b/certweb/pubkeys.py @@ -54,6 +54,10 @@ def get_pubkey(id, check_user=True): @bp.route('/create', methods=('GET', 'POST')) @login_required def create(): + db = get_db() + user = db.execute( + 'SELECT * FROM user WHERE id = ?', (g.user['id'],) + ).fetchone() if request.method == 'POST': key_name = request.form['key_name'] ssh_pubkey = request.form['ssh_pubkey'] @@ -64,11 +68,11 @@ def create(): fingerprint = str(base64.b64encode(hashlib.sha256(base64.b64decode(key)).digest()), "utf-8").rstrip('=') print(fingerprint) - db = get_db() ckfp = db.execute( 'SELECT id, fingerprint, deleted FROM pubkeys WHERE fingerprint = ?', (fingerprint, ) ).fetchone() + if ckfp != None: if ckfp['fingerprint'] == fingerprint: if ckfp['deleted'] == 0: @@ -96,13 +100,17 @@ def create(): db.commit() return redirect(url_for('pubkeys.index')) - return render_template('pubkeys/create.html') + return render_template('pubkeys/create.html', user=user) @bp.route('//update', methods=('GET', 'POST')) @login_required def update(id): pubkey = get_pubkey(id) + db = get_db() + user = db.execute( + 'SELECT * FROM user WHERE id = ?', (g.user['id'],) + ).fetchone() if request.method == 'POST': key_name = request.form['key_name'] deleted = request.form.get('deleted') @@ -118,7 +126,6 @@ def update(id): if error is not None: flash(error) else: - db = get_db() db.execute( 'UPDATE pubkeys SET key_name = ?, deleted = ?' ' WHERE id = ?', @@ -127,7 +134,7 @@ def update(id): db.commit() return redirect(url_for('pubkeys.index')) - return render_template('pubkeys/update.html', pubkey=pubkey) + return render_template('pubkeys/update.html', pubkey=pubkey, user=user) @bp.route('//delete', methods=('GET',)) @login_required diff --git a/certweb/static/style.css b/certweb/static/style.css index aa26027..83c4edf 100644 --- a/certweb/static/style.css +++ b/certweb/static/style.css @@ -29,3 +29,4 @@ nav ul li a, nav ul li span, header .action { display: block; padding: 0.5rem; } .danger { color: #cc2f2e; } input.danger { color: #cc2f2e; } input[type=submit] { align-self: start; min-width: 10em; } +.key { color: #cc22ff; } diff --git a/certweb/templates/pubkeys/index.html b/certweb/templates/pubkeys/index.html index 5b6fea8..ea8c062 100644 --- a/certweb/templates/pubkeys/index.html +++ b/certweb/templates/pubkeys/index.html @@ -45,7 +45,7 @@ {% endif %}
fingerprint: {{ pubkey['fingerprint'] }}

-
{{ request.form['ssh_pubkey'] or pubkey['ssh_pubkey'] }}
+
{{ request.form['ssh_pubkey'] or pubkey['ssh_pubkey'] }}

registered on {{ pubkey['created'].strftime('%Y-%m-%d') }}