diff --git a/db/sqlite.py b/db/sqlite.py index 9740440..4b9ab32 100644 --- a/db/sqlite.py +++ b/db/sqlite.py @@ -122,7 +122,7 @@ class DB: return self._db().execute(''' select user_id, password from users - where name = ? + where name = lower(?) ''', (username,) ).fetchone() @@ -138,7 +138,7 @@ class DB: def get_user_private_info(self, user_id): return self._db().execute(''' - select about + select name, about from users where user_id = ? ''', @@ -156,6 +156,15 @@ class DB: ) db.commit() + def get_user_name(self, user_id): + return self._db().execute(''' + select name + from users + where user_id = ? + ''', + (user_id,) + ).fetchone() + def add_thread(self, author_id, forum_id, title, text, time): db = self._db() c = db.cursor() @@ -288,7 +297,7 @@ class DB: c = db.cursor() c.execute(''' insert into users(name, password, join_time) - values (?, ?, ?) + values (lower(?), ?, ?) ''', (username, password, time) ) diff --git a/main.py b/main.py index 7ed2a30..efceab0 100644 --- a/main.py +++ b/main.py @@ -75,7 +75,6 @@ def login(): if verify_password(request.form['password'], hash): flash('Logged in', 'success') session['user_id'] = id - session['username'] = request.form['username'] return redirect(url_for('index')) else: # Sleep to reduce effectiveness of bruteforce @@ -98,12 +97,14 @@ def user_edit(): if request.method == 'POST': about = request.form['about'].replace('\r', '') db.set_user_private_info(user_id, about) + name, = db.get_user_name(user_id) + flash('Updated profile', 'success') else: - about, = db.get_user_private_info(user_id) + name, about = db.get_user_private_info(user_id) return render_template( 'user_edit.html', - name = session.get('username', '???'), + name = name, title = 'Edit profile', about = about ) diff --git a/templates/base.html b/templates/base.html index 8bff4a4..331a161 100644 --- a/templates/base.html +++ b/templates/base.html @@ -10,7 +10,7 @@
{% if 'user_id' in session %} - {{ session.get('username', '???') }} + User panel | Logout {% else %} diff --git a/templates/user_edit.html b/templates/user_edit.html index 73079d9..4c3a78f 100644 --- a/templates/user_edit.html +++ b/templates/user_edit.html @@ -1,9 +1,13 @@ {% extends 'base.html' %} {% block content %} +

View public profile

-

{{ name }}

-

-

+ + + + +
Username{{ name }}
ID{{ session['user_id'] }}
About
+ {% endblock %} diff --git a/test/init_db.txt b/test/init_db.txt index a7e8162..b77856d 100644 --- a/test/init_db.txt +++ b/test/init_db.txt @@ -1,12 +1,12 @@ insert into users (name, password, email, join_time) values ( - "Foo", + "foo", -- supasecret "$argon2id$v=19$m=65536,t=3,p=4$qBWCEAKgdA4BYOy915qzlg$KhGy3UF0QMlplt2eB7r7QNL2kDcggXUimRWUrWql8sI", "foo@bar.baz", 0 ); insert into users (name, password, email, join_time) values ( - "Bar", + "bar", -- abraca "$argon2id$v=19$m=65536,t=3,p=4$klJKCUFoDaF07j3nPCeEUA$lCphd5n1YIs8MaVop2vGNirwknkh91qJIZHMuBOlgWA", "bar@foo.baz",